[libcxx-commits] [PATCH] D89003: [libc++] Add caching for feature-detection Lit tests
Louis Dionne via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 8 18:09:11 PDT 2020
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5390c5a96e97: [libc++] Add caching for feature-detection Lit tests (authored by ldionne).
Changed prior to commit:
https://reviews.llvm.org/D89003?vs=296784&id=297094#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89003/new/
https://reviews.llvm.org/D89003
Files:
libcxx/utils/libcxx/test/dsl.py
Index: libcxx/utils/libcxx/test/dsl.py
===================================================================
--- libcxx/utils/libcxx/test/dsl.py
+++ libcxx/utils/libcxx/test/dsl.py
@@ -20,13 +20,27 @@
import lit.util
-def _memoize(f):
- cache = dict()
- def memoized(x):
- if x not in cache:
- cache[x] = f(x)
- return cache[x]
- return memoized
+def _memoizeExpensiveOperation(extractCacheKey):
+ """
+ Allows memoizing a very expensive operation.
+
+ The caching is implemented as a list, and we search linearly for existing
+ entries. This is incredibly naive, however this allows the cache keys to
+ contain lists and other non-hashable objects. Assuming the operation we're
+ memoizing is very expensive, this is still a win anyway.
+ """
+ def decorator(function):
+ cache = []
+ def f(*args, **kwargs):
+ cacheKey = extractCacheKey(*args, **kwargs)
+ try:
+ result = next(res for (key, res) in cache if key == cacheKey)
+ except StopIteration: # This wasn't in the cache
+ result = function(*args, **kwargs)
+ cache.append((cacheKey, result))
+ return result
+ return f
+ return decorator
def _executeScriptInternal(test, commands):
"""
@@ -72,6 +86,7 @@
def __exit__(self, *args): os.remove(tmp.name)
return TestWrapper(suite, pathInSuite, config)
+ at _memoizeExpensiveOperation(lambda c, s: (c.substitutions, c.environment, s))
def sourceBuilds(config, source):
"""
Return whether the program in the given string builds successfully.
@@ -88,6 +103,7 @@
_executeScriptInternal(test, ['rm %t.exe'])
return exitCode == 0
+ at _memoizeExpensiveOperation(lambda c, p, args=None, testPrefix='': (c.substitutions, c.environment, p, args))
def programOutput(config, program, args=None, testPrefix=''):
"""
Compiles a program for the test target, run it on the test target and return
@@ -122,6 +138,7 @@
finally:
_executeScriptInternal(test, ['rm %t.exe'])
+ at _memoizeExpensiveOperation(lambda c, f: (c.substitutions, c.environment, f))
def hasCompileFlag(config, flag):
"""
Return whether the compiler in the configuration supports a given compiler flag.
@@ -135,6 +152,7 @@
])
return exitCode == 0
+ at _memoizeExpensiveOperation(lambda c, l: (c.substitutions, c.environment, l))
def hasLocale(config, locale):
"""
Return whether the runtime execution environment supports a given locale.
@@ -153,6 +171,7 @@
return programOutput(config, program, args=[pipes.quote(locale)],
testPrefix="check_locale_" + locale) is not None
+ at _memoizeExpensiveOperation(lambda c, flags='': (c.substitutions, c.environment, flags))
def compilerMacros(config, flags=''):
"""
Return a dictionary of predefined compiler macros.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89003.297094.patch
Type: text/x-patch
Size: 2794 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201009/9367cffa/attachment.bin>
More information about the libcxx-commits
mailing list