Commit Graph

14 Commits

Author SHA1 Message Date
Erik Eckstein
e95283ba38 SwiftCompilerSources: make the testing infrastructure available in the SIL module
add `Test`, which is the SIL-equivalent of `FunctionTest`.
It's invocation closure gets a `TestContext` instead of a `FunctionContext`.

^ The commit message #2 will be skipped:

^ - test
2025-07-28 14:19:10 +02:00
Erik Eckstein
65c9828cb3 SwiftCompilerSources: move the Context protocols from the Optimizer to the SIL module
This allows to move many SIL APIs and utilities, which require a context, to the SIL module.

The SIL-part of SwiftPassInvocation is extracted into a base class SILContext which now lives in SIL.

Also: simplify the begin/end-pass functions of the SwiftPassInvocation.
2025-07-28 14:19:07 +02:00
Nate Chandler
365c1a0286 [Test] Provide dead-end blocks to SIL tests.
Via a new method on the dependencies struct.
2024-07-03 15:27:00 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Nate Chandler
c84e196b16 [Test] Reenable SIL unit tests on windows.
Use `fflush(stdout)` from C++.

Issue 73252.
2024-05-06 12:20:16 -07:00
Andrew Trick
e271973246 Fix FunctionTest memory corruption in SwiftCompilerSouces.
A FunctionTest created in Swift source has no persistent storage
address. This results in sporadic crashes when running unit tests.

Fix the FunctionTest registry to store the value of the test.

Eventually, we could probably rig something up with @_rawLayout, but
it makes more sense for FunctionTest to be a value type anyway.
2024-01-20 09:44:23 -08:00
Andrew Trick
5e9123978c Fix compiler Test Registry to use a StringMap.
We have no guarantee that the StringRef passed to the registry lives
in the static data segment.

This resulted in memory corruption during bootstrapping, which is
particularly difficult to diagnose and reproduce.
2024-01-20 07:51:06 -08:00
Nate Chandler
73d57c9012 [Test] Avoid LSAN report of leaked FunctionTest.
Avoid heap-allocating an immortal FunctionTest with `new` because it
results in LSAN reporting a leak.

In fact, the "leaked" value wasn't leaked: a reference to it was stored
in a global map when the type's constructor ran.  It was only a leak in
the sense that it was never freed, not that there was a dangling
allocation which couldn't be freed.

Work around this by storing the global instances themselves in a second
static structure.  Store pointers to the instances into the global map
as before.

rdar://118134637
2023-11-14 15:05:18 -08:00
Andrew Trick
727ff71476 Rename FunctionTest::getInvocation.
The test invocation is something completely different in this context.
2023-10-10 13:40:02 -07:00
Nate Chandler
9ca6b9ac1f [Test] Print to stdout.
In the C++ sources it is slightly more convenient to dump to stderr than
to print to stdout, but it is rather more unsightly to print to stderr
from the Swift sources.  Switch to stdout.  Also allows the dump
functions to be marked debug only.
2023-10-10 08:19:44 -07:00
Nate Chandler
ae1f950315 [SwiftCompilerSources] Moved Test into Optimizer.
And changed the type of the context argument to FunctionPassContext.
2023-10-07 21:23:13 -07:00
Nate Chandler
ce4ba6ce2a [Test] Simplified registration.
At the cost of adding an unsafe bitcast implementation detail,
simplified the code involved to register a new FunctionTest when adding
one.

Also simplifies how Swift native `FunctionTest`s are registered with the
C++ registry.

Now, the to-be-executed thin closure for native Swift `FunctionTest`s is
stored under within the swift::test::FunctionTest instance corresponding
to it.  Because its type isn't representable in C++, `void *` is used
instead.  When the FunctionTest is invoked, a thunk is called which
takes the actual test function and bridged versions of the arguments.
That thunk unwraps the arguments, casts the stored function to the
appropriate type, and invokes it.

Thanks to Andrew Trick for the idea.
2023-10-05 18:02:35 -07:00
Nate Chandler
dab8c146a6 [SwiftCompilerSources] Bridged in-IR testing.
Added the bridging types involved and the basic functionality.
2023-09-28 11:33:50 -07:00
Nate Chandler
e9ab3b4b53 [Test] Refactored SIL "unit" tests.
Renamed UnitTest to FunctionTest.

FunctionTests are now instantiated once as global objects--with their
names and the code they are to run--at which time they are stored by
name in a global registry.

Moved the types to the SIL library.

Together, these changes enable defining unit tests in the source file
containing the code to be tested.
2023-07-04 11:52:11 -07:00