[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
Wed Oct 7 13:55:28 PDT 2020
ldionne created this revision.
ldionne added a reviewer: arichardson.
Herald added subscribers: libcxx-commits, dexonsmith, jkorous.
Herald added a project: libc++.
Herald added a reviewer: libc++.
ldionne requested review of this revision.
This significantly speeds up the configuration of libc++'s test suite
by making sure that we don't perform the same operations over and over
again.
Repository:
rG LLVM Github Monorepo
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, 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.296784.patch
Type: text/x-patch
Size: 2786 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201007/c64ac270/attachment-0001.bin>
More information about the libcxx-commits
mailing list