internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: facebookresearch/CompilerGym

Issue:
[llvm] "./a.out: Permission denied" error for runtime observations in Google Colaboratory
## 🐛 Bug

I'm not sure if this is a security feature of colab (preventing execution of arbitrary binaries) or a problem that we can fix in CompilerGym.

## To Reproduce

```py
import compiler_gym
env = compiler_gym.make("llvm-v0")
env.reset()
env.observation.Runtime()
```

[Demo notebook](https://colab.research.google.com/drive/1m-W3Qy0swiD8P4YvpfX6SP6UYSFWVhnH?usp=sharing).

## Environment

Please fill in this checklist:

- CompilerGym: v0.2.0
- How you installed CompilerGym (conda, pip, source): pip


Discussion:
I was able to reproduce a similar issue in a docker container, and it turned out the problem was that executables in `/dev/shm` are not executable. It would be worth setting a different transient cache and seeing if the problem still holds in colab.

Cheers,
Chris

Resolving patch:
diff --git a/compiler_gym/envs/llvm/datasets/cbench.py b/compiler_gym/envs/llvm/datasets/cbench.py
--- a/compiler_gym/envs/llvm/datasets/cbench.py
+++ b/compiler_gym/envs/llvm/datasets/cbench.py
@@ -288,7 +288,7 @@ def _make_cBench_validator(
     def validator_cb(env: "LlvmEnv") -> Optional[ValidationError]:  # noqa: F821
         """The validation callback."""
         with _CBENCH_DOWNLOAD_THREAD_LOCK:
-            with fasteners.InterProcessLock(cache_path("cbench-v1-runtime-data.LOCK")):
+            with fasteners.InterProcessLock(cache_path(".cbench-v1-runtime-data.LOCK")):
                 download_cBench_runtime_data()
 
         cbench_data = site_data_path("llvm-v0/cbench-v1-runtime-data/runtime_data")
@@ -557,7 +557,7 @@ def __init__(self, site_data_base: Path):
     def install(self):
         super().install()
         with _CBENCH_DOWNLOAD_THREAD_LOCK:
-            with fasteners.InterProcessLock(cache_path("cbench-v1-runtime-data.LOCK")):
+            with fasteners.InterProcessLock(cache_path(".cbench-v1-runtime-data.LOCK")):
                 download_cBench_runtime_data()
 
 


Test patch:
Repository: facebookresearch/CompilerGym

Issue:
Documentation for compiler_gym.wrappers is incomplete
## 📚 Documentation

The module docstring for `compiler_gym/wrappers/__init__.py` simply reads:

> The `compiler_gym.wrappers` module provides.

👎 


Discussion:

Resolving patch:
diff --git a/compiler_gym/wrappers/__init__.py b/compiler_gym/wrappers/__init__.py
--- a/compiler_gym/wrappers/__init__.py
+++ b/compiler_gym/wrappers/__init__.py
@@ -2,7 +2,30 @@
 #
 # This source code is licensed under the MIT license found in the
 # LICENSE file in the root directory of this source tree.
-"""The :code:`compiler_gym.wrappers` module provides.
+"""The :code:`compiler_gym.wrappers` module provides a set of classes that can
+be used to transform an environment in a modular way.
+
+For example:
+
+    >>> env = compiler_gym.make("llvm-v0")
+    >>> env = TimeLimit(env, n=10)
+    >>> env = CycleOverBenchmarks(
+    ...     env,
+    ...     benchmarks=[
+    ...         "benchmark://cbench-v1/crc32",
+    ...         "benchmark://cbench-v1/qsort",
+    ...     ],
+    ... )
+
+.. warning::
+
+    CompilerGym environments are incompatible with the `OpenAI Gym wrappers
+    <https://github.com/openai/gym/tree/master/gym/wrappers>`_. This is because
+    CompilerGym extends the environment API with additional arguments and
+    methods. You must use the wrappers from this module when wrapping
+    CompilerGym environments. We provide a set of base wrappers that are
+    equivalent to those in OpenAI Gym that you can use to write your own
+    wrappers.
 """
 from compiler_gym.wrappers.commandline import (
     CommandlineWithTerminalAction,
diff --git a/compiler_gym/wrappers/datasets.py b/compiler_gym/wrappers/datasets.py
--- a/compiler_gym/wrappers/datasets.py
+++ b/compiler_gym/wrappers/datasets.py
@@ -157,9 +157,11 @@ class RandomOrderBenchmarks(IterateOverBenchmarks):
     .. note::
 
         Uniform random selection is provided by evaluating the input benchmarks
-        iterator into a list and sampling randomly from the list. This will not
-        work for random iteration over infinite or very large iterables of
-        benchmarks.
+        iterator into a list and sampling randomly from the list. For very large
+        and infinite iterables of benchmarks you must use the
+        :class:`IterateOverBenchmarks
+        <compiler_gym.wrappers.IterateOverBenchmarks>` wrapper with your own
+        random sampling iterator.
     """
 
     def __init__(


Test patch:
Repository: facebookresearch/CompilerGym

Issue:
Improve examples documentation to make it clear that they are standalone
## 🚀 Feature

Tangentially to #532, I think it would be good to add a "Usage" section to examples/README.md that makes it clear that these example scripts can be used through pip-installed CompilerGym, and possibly split the examples rules out of the top level makefile into an examples/Makefile file for standalone usage.

## Motivation

It is not clear whether the included examples require building from source (they don't) or can be used on their own (they can).


Discussion:

Resolving patch:
diff --git a/examples/setup.py b/examples/setup.py
--- a/examples/setup.py
+++ b/examples/setup.py
@@ -13,6 +13,8 @@
     version = f.read().strip()
 with open("requirements.txt") as f:
     requirements = [ln.split("#")[0].rstrip() for ln in f.readlines()]
+with open("../tests/requirements.txt") as f:
+    requirements += [ln.split("#")[0].rstrip() for ln in f.readlines()]
 
 setuptools.setup(
     name="compiler_gym_examples",


Test patch:
Repository: facebookresearch/CompilerGym

Issue:
`statistics.py` wrong parameter name
## 🐛 Bug

The functions [here](https://github.com/facebookresearch/CompilerGym/blob/e248330d2475fbcdf473cc3df951f25b5eaf4945/compiler_gym/util/statistics.py#L8) says they take `iterable` as inputs. However, `np.asarray` actually take `array_like`.

[Quote:
](https://numpy.org/doc/stable/reference/generated/numpy.asarray.html)

> Input data, in any form that can be converted to an array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays.

e.g.
```python
geometric_mean(i for i in range(10))
```
This will fail because though it's an `iterable`, it's not an `array_like`.


Discussion:

Resolving patch:
diff --git a/compiler_gym/util/statistics.py b/compiler_gym/util/statistics.py
--- a/compiler_gym/util/statistics.py
+++ b/compiler_gym/util/statistics.py
@@ -5,9 +5,9 @@
 import numpy as np
 
 
-def geometric_mean(iterable):
+def geometric_mean(array_like):
     """Zero-length-safe geometric mean."""
-    values = np.asarray(iterable)
+    values = np.asarray(array_like)
     if not values.size:
         return 0
     # Shortcut to return 0 when any element of the input is not positive.
@@ -17,17 +17,17 @@ def geometric_mean(iterable):
     return np.exp(a.sum() / len(a))
 
 
-def arithmetic_mean(iterable):
+def arithmetic_mean(array_like):
     """Zero-length-safe arithmetic mean."""
-    values = np.asarray(iterable)
+    values = np.asarray(array_like)
     if not values.size:
         return 0
     return values.mean()
 
 
-def stdev(iterable):
+def stdev(array_like):
     """Zero-length-safe standard deviation."""
-    values = np.asarray(iterable)
+    values = np.asarray(array_like)
     if not values.size:
         return 0
     return values.std()


Test patch:
Repository: facebookresearch/CompilerGym

Issue:
Cache path inconsistency in cc and python?
I noticed that theses two files are using different conventions for creating cache paths. The cc file says the python file should align with the cc file, but they are still different. Is this intended?

https://github.com/facebookresearch/CompilerGym/blob/61f460fadee2454ff8fca3bbd5a5d338854cc4a2/compiler_gym/util/runfiles_path.py#L101-L105

https://github.com/facebookresearch/CompilerGym/blob/1596776ad35a7aeca45ed85b2e073af824844e29/compiler_gym/util/RunfilesPath.cc#L61-L65


Discussion:
Hi @uduse, that is a bug! Please patch the .py file. They should both be `~/.local/cache/compiler_gym`.

Thanks for the report, good catch!

Cheers,
Chris

Resolving patch:
diff --git a/compiler_gym/util/runfiles_path.py b/compiler_gym/util/runfiles_path.py
--- a/compiler_gym/util/runfiles_path.py
+++ b/compiler_gym/util/runfiles_path.py
@@ -100,7 +100,7 @@ def cache_path(relpath: str) -> Path:
     if forced:
         return Path(forced) / relpath
     elif os.environ.get("HOME"):
-        return Path("~/.cache/compiler_gym").expanduser() / relpath
+        return Path("~/.local/cache/compiler_gym").expanduser() / relpath
     else:
         return Path(f"/tmp/compiler_gym_{getuser()}/cache") / relpath
 


Test patch:
Repository: facebookresearch/CompilerGym

Issue:
Bug in llvm_rl benchmark when setting a max_benchmarks
https://github.com/facebookresearch/CompilerGym/blob/b803856257aa663b20a26e49125d5d603f84a9b9/examples/llvm_rl/model/benchmarks.py#L96-L98

should be

`n = min(self.max_benchmarks, n)`
Bug in llvm_rl benchmark when setting a max_benchmarks
https://github.com/facebookresearch/CompilerGym/blob/b803856257aa663b20a26e49125d5d603f84a9b9/examples/llvm_rl/model/benchmarks.py#L96-L98

should be

`n = min(self.max_benchmarks, n)`


Discussion:
Good catch, please submit a PR!

Cheers,
Chris
Good catch, please submit a PR!

Cheers,
Chris

Resolving patch:
diff --git a/examples/llvm_rl/model/benchmarks.py b/examples/llvm_rl/model/benchmarks.py
--- a/examples/llvm_rl/model/benchmarks.py
+++ b/examples/llvm_rl/model/benchmarks.py
@@ -95,7 +95,7 @@ def _uris_iterator(
         start = self.benchmarks_start_at
         n = len(self.uris)
         if self.max_benchmarks:
-            n = min(len(self.uris), n)
+            n = min(self.max_benchmarks, n)
 
         if uris:
             # Shortcut in case we already have a list of URIs that we can slice


Test patch:
Repository: falconry/falcon

Issue:
Remove responder exception handling
Can hide problems, encourage bad coding practices.



Discussion:

Resolving patch:
diff --git a/falcon/api.py b/falcon/api.py
--- a/falcon/api.py
+++ b/falcon/api.py
@@ -16,8 +16,6 @@
 
 """
 
-import traceback
-
 from .request import Request
 from .response import Response
 from . import responders
@@ -69,25 +67,6 @@ def __call__(self, env, start_response):
             if req.client_accepts_json():
                 resp.body = ex.json()
 
-        except Exception as ex:
-            # Reset to a known state and respond with a generic error
-            req = Request(env)
-            resp = Response()
-
-            message = ['Responder raised ', ex.__class__.__name__]
-
-            details = str(ex)
-            if details:
-                message.append(': ')
-                message.append(details)
-
-            stack = traceback.format_exc()
-            message.append('\n')
-            message.append(stack)
-
-            req.log_error(''.join(message))
-            responders.server_error(req, resp)
-
         #
         # Set status and headers
         #


Test patch:
diff --git a/tests/test_wsgi_errors.py b/tests/test_wsgi_errors.py
--- a/tests/test_wsgi_errors.py
+++ b/tests/test_wsgi_errors.py
@@ -10,15 +10,6 @@
     str_message = 'UTF-8: \xc2\x80'
 
 
-class BombResource:
-
-    def on_get(self, req, resp):
-        raise IOError()
-
-    def on_head(self, req, resp):
-        raise MemoryError("I can't remember a thing.")
-
-
 class LoggerResource:
 
     def on_get(self, req, resp):
@@ -31,10 +22,8 @@ def on_head(self, req, resp):
 class TestWSGIError(helpers.TestSuite):
 
     def prepare(self):
-        self.tehbomb = BombResource()
         self.tehlogger = LoggerResource()
 
-        self.api.add_route('/bomb', self.tehbomb)
         self.api.add_route('/logger', self.tehlogger)
 
         self.wsgierrors_buffer = io.BytesIO()
@@ -48,21 +37,6 @@ def prepare(self):
             # with undefined encoding, so do the encoding manually.
             self.wsgierrors = self.wsgierrors_buffer
 
-    def test_exception_logged(self):
-        self._simulate_request('/bomb', wsgierrors=self.wsgierrors)
-
-        log = self.wsgierrors_buffer.getvalue()
-        self.assertIn(b'IOError', log)
-
-    def test_exception_logged_with_details(self):
-        self._simulate_request('/bomb', wsgierrors=self.wsgierrors,
-                               method='HEAD')
-
-        log = self.wsgierrors_buffer.getvalue()
-
-        self.assertIn(b'MemoryError', log)
-        self.assertIn(b'remember a thing', log)
-
     def test_responder_logged_unicode(self):
         self._simulate_request('/logger', wsgierrors=self.wsgierrors)
Repository: falconry/falcon

Issue:
Provide a way to access query params from POST data



Discussion:
RESTful API seldom use HTTP form params, and falcon primarily focus on building RESTful API.


Resolving patch:
diff --git a/falcon/request.py b/falcon/request.py
--- a/falcon/request.py
+++ b/falcon/request.py
@@ -100,13 +100,18 @@ def __init__(self, env):
         else:
             self.query_string = ''
 
+        self._headers = helpers.parse_headers(env)
+
         # PERF: Don't parse it if we don't have to!
         if self.query_string:
             self._params = helpers.parse_query_string(self.query_string)
         else:
             self._params = {}
 
-        self._headers = helpers.parse_headers(env)
+        if (self.content_type and
+            self.content_type.split(';')[0] == 'application/x-www-form-urlencoded'):
+            body = self.stream.read(self.content_length)
+            self._params.update(helpers.parse_query_string(body))
 
     def log_error(self, message):  # pragma: no cover
         """Log an error to wsgi.error


Test patch:
diff --git a/falcon/tests/test_query_params.py b/falcon/tests/test_query_params.py
--- a/falcon/tests/test_query_params.py
+++ b/falcon/tests/test_query_params.py
@@ -2,7 +2,7 @@
 import falcon.testing as testing
 
 
-class TestQueryParams(testing.TestBase):
+class _TestQueryParams(testing.TestBase):
 
     def before(self):
         self.resource = testing.TestResource()
@@ -218,3 +218,13 @@ def test_bogus_input(self):
                           ['red', 'green', ''])
         self.assertEquals(req.get_param('limit'), '1')
         self.assertIs(req.get_param('pickle'), None)
+
+class PostQueryParams(_TestQueryParams):
+    def simulate_request(self, path, query_string):
+        headers = {"Content-Type": "application/x-www-form-urlencoded"}
+        super(PostQueryParams, self).simulate_request(path, body=query_string,
+                                                      headers=headers)
+
+class GetQueryParams(_TestQueryParams):
+    def simulate_request(self, path, query_string):
+        super(GetQueryParams, self).simulate_request(path, query_string=query_string)
Repository: falconry/falcon

Issue:
Update to_query_str to intelligently handle lists



Discussion:

Resolving patch:
diff --git a/falcon/util.py b/falcon/util.py
--- a/falcon/util.py
+++ b/falcon/util.py
@@ -63,7 +63,8 @@ def to_query_str(params):
     Args:
         params: dict of simple key-value types, where key is a string and
             value is a string or something that can be converted into a
-            string.
+            string. If value is a list, it will be converted to a comma-
+            delimited string (e.g., thing=1,2,3)
 
     Returns:
         A URI query string starting with '?', or and empty string if there
@@ -81,6 +82,8 @@ def to_query_str(params):
             v = 'true'
         elif v is False:
             v = 'false'
+        elif isinstance(v, list):
+            v = ','.join([str(i) for i in v])
         else:
             v = str(v)
 


Test patch:
diff --git a/falcon/tests/test_utils.py b/falcon/tests/test_utils.py
--- a/falcon/tests/test_utils.py
+++ b/falcon/tests/test_utils.py
@@ -34,6 +34,18 @@ def test_pack_query_params_one(self):
             falcon.to_query_str({'limit': 10}),
             '?limit=10')
 
+        self.assertEquals(
+            falcon.to_query_str({'things': [1, 2, 3]}),
+            '?things=1,2,3')
+
+        self.assertEquals(
+            falcon.to_query_str({'things': ['a']}),
+            '?things=a')
+
+        self.assertEquals(
+            falcon.to_query_str({'things': ['a', 'b']}),
+            '?things=a,b')
+
     def test_pack_query_params_several(self):
         garbage_in = {
             'limit': 17,
Repository: falconry/falcon

Issue:
Not all modules are cythonized
Missing some modules, such as hooks and those in the util package.



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,8 +1,12 @@
+import glob
 import imp
 import io
-import sys
+import os
 from os import path
 from setuptools import setup, find_packages, Extension
+import sys
+
+MYDIR = path.abspath(os.path.dirname(__file__))
 
 VERSION = imp.load_source('version', path.join('.', 'falcon', 'version.py'))
 VERSION = VERSION.__version__
@@ -29,22 +33,29 @@
         CYTHON = False
 
 if CYTHON:
-    ext_names = (
-        'api',
-        'api_helpers',
-        'errors',
-        'http_error',
-        'request',
-        'request_helpers',
-        'responders',
-        'response',
-        'response_helpers',
-    )
+    def list_modules(dirname):
+        filenames = glob.glob(path.join(dirname, '*.py'))
+
+        module_names = []
+        for name in filenames:
+            module, ext = path.splitext(path.basename(name))
+            if module != '__init__':
+                module_names.append(module)
+
+        return module_names
 
-    cmdclass = {'build_ext': build_ext}
     ext_modules = [
         Extension('falcon.' + ext, [path.join('falcon', ext + '.py')])
-        for ext in ext_names]
+        for ext in list_modules(path.join(MYDIR, 'falcon'))]
+
+    ext_modules += [
+        Extension('falcon.util.' + ext,
+                  [path.join('falcon', 'util', ext + '.py')])
+
+        for ext in list_modules(path.join(MYDIR, 'falcon', 'util'))]
+
+    cmdclass = {'build_ext': build_ext}
+
 else:
     cmdclass = {}
     ext_modules = []


Test patch:
Repository: falconry/falcon

Issue:
HTTP Range support is incomplete
in the HTTP RFC 2616, a range header must be written with the format
Range: bytes=0-1,3-4,6-7

I understand that falcon does not support multiple ranges (and I do not need it personally), but it currently does not even support stripping the "bytes=" from the header before trying a transformation.
Here is the code of the range attribute:
https://github.com/racker/falcon/blob/2fbe618d486c977df2bb7d7240386aa4a5f781c1/falcon/request.py#L340

A simple fix would be to strip the "bytes=" if present at the start of the header's value.



Discussion:

Resolving patch:
diff --git a/falcon/request.py b/falcon/request.py
--- a/falcon/request.py
+++ b/falcon/request.py
@@ -340,6 +340,8 @@ def date(self):
     def range(self):
         try:
             value = self.env['HTTP_RANGE']
+            if value.startswith('bytes='):
+                value = value[6:]
         except KeyError:
             return None
 


Test patch:
diff --git a/tests/test_req_vars.py b/tests/test_req_vars.py
--- a/tests/test_req_vars.py
+++ b/tests/test_req_vars.py
@@ -380,6 +380,10 @@ def test_range(self):
         req = Request(testing.create_environ(headers=headers))
         self.assertEqual(req.range, (-10240, -1))
 
+        headers = {'Range': 'bytes=0-2'}
+        req = Request(testing.create_environ(headers=headers))
+        self.assertEqual(req.range, (0, 2))
+
         headers = {'Range': ''}
         req = Request(testing.create_environ(headers=headers))
         self.assertRaises(falcon.HTTPInvalidHeader, lambda: req.range)
Repository: falconry/falcon

Issue:
Request.get_header raises the wrong exception
Found an issue that is making exception-handling not very intuitive when dealing with required headers...

```
try:
  my_header = req.get_header('My-Header', required=True)
except falcon.HTTPMissingHeader:
  print 'Missing header'
except falcon.HTTPMissingParam:
  print 'Missing param'
# Prints "Missing param"
```

Basically, calling `get_header()` with `required=True` should raise a `HTTPMissingHeader` exception, when actually what gets raised is `HTTPMissingParam`.

This also leads to confusing error response messages, since the response title and header refer to a missing, required "query parameter" instead of a "header".



Discussion:
OK, I found the test that was masking this and was able to repro. Fixing now.


Resolving patch:
diff --git a/falcon/request.py b/falcon/request.py
--- a/falcon/request.py
+++ b/falcon/request.py
@@ -599,7 +599,7 @@ def get_header(self, name, required=False):
             if not required:
                 return None
 
-            raise HTTPMissingParam(name)
+            raise HTTPMissingHeader(name)
 
     def get_header_as_datetime(self, header, required=False):
         """Return an HTTP header with HTTP-Date values as a datetime.


Test patch:
diff --git a/tests/test_headers.py b/tests/test_headers.py
--- a/tests/test_headers.py
+++ b/tests/test_headers.py
@@ -183,9 +183,14 @@ def test_default_value(self):
     def test_required_header(self):
         self.simulate_request(self.test_route)
 
-        self.assertRaises(falcon.HTTPBadRequest,
-                          self.resource.req.get_header, 'X-Not-Found',
-                          required=True)
+        try:
+            self.resource.req.get_header('X-Not-Found', required=True)
+            self.fail('falcon.HTTPMissingHeader not raised')
+        except falcon.HTTPMissingHeader as ex:
+            self.assertIsInstance(ex, falcon.HTTPBadRequest)
+            self.assertEqual(ex.title, 'Missing header value')
+            expected_desc = 'The X-Not-Found header is required.'
+            self.assertEqual(ex.description, expected_desc)
 
     def test_no_body_on_100(self):
         self.resource = StatusTestResource(falcon.HTTP_100)
diff --git a/tests/test_query_params.py b/tests/test_query_params.py
--- a/tests/test_query_params.py
+++ b/tests/test_query_params.py
@@ -94,6 +94,7 @@ def test_required(self, method_name):
             getattr(req, method_name)('marker', required=True)
             self.fail('falcon.HTTPMissingParam not raised')
         except falcon.HTTPMissingParam as ex:
+            self.assertIsInstance(ex, falcon.HTTPBadRequest)
             self.assertEqual(ex.title, 'Missing query parameter')
             expected_desc = 'The "marker" query parameter is required.'
             self.assertEqual(ex.description, expected_desc)
Repository: falconry/falcon

Issue:
Missing HTTP status codes
There's a few status codes from here http://tools.ietf.org/html/rfc6585 that could be great including.

429 Too many requests for instance.



Discussion:
@chripede cool, sounds like a good idea. If you'd like to go ahead and nock this out, the codes are all defined in falcon/util/status_codes.py and documented in doc/api/status.rst


Resolving patch:
diff --git a/falcon/status_codes.py b/falcon/status_codes.py
--- a/falcon/status_codes.py
+++ b/falcon/status_codes.py
@@ -90,6 +90,12 @@
 HTTP_IM_A_TEAPOT = HTTP_418
 HTTP_426 = '426 Upgrade Required'
 HTTP_UPGRADE_REQUIRED = HTTP_426
+HTTP_428 = '428 Precondition Required'
+HTTP_PRECONDITION_REQUIRED = HTTP_428
+HTTP_429 = '429 Too Many Requests'
+HTTP_TOO_MANY_REQUESTS = HTTP_429
+HTTP_431 = '431 Request Header Fields Too Large'
+HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = HTTP_431
 
 HTTP_500 = '500 Internal Server Error'
 HTTP_INTERNAL_SERVER_ERROR = HTTP_500
@@ -103,6 +109,8 @@
 HTTP_GATEWAY_TIMEOUT = HTTP_504
 HTTP_505 = '505 HTTP Version not supported'
 HTTP_HTTP_VERSION_NOT_SUPPORTED = HTTP_505
+HTTP_511 = '511 Network Authentication Required'
+HTTP_NETWORK_AUTHENTICATION_REQUIRED = HTTP_511
 
 # 70X - Inexcusable
 HTTP_701 = '701 Meh'


Test patch: