Commit Graph

198 Commits

Author SHA1 Message Date
Slava Pestov
140bfd6b2f Sema: Fix infinite loop in OrderDeclarations::operator()
If the two declarations were in different source files, we would get
stuck in the while loop at the end.

Fixes rdar://164519548.
2025-11-21 21:46:19 -05:00
Henrik G. Olsson
1066c8252a Merge pull request #84930 from ramonasuncion/test-multifile-stderr-redirect
[Test][multifile] Replace process substitution with file redirect
2025-11-10 04:49:41 +00:00
Ramon Asuncion
d7fdebbe12 [Test][multifile] Use --input-file and make FileCheck check Int|String 2025-11-05 22:44:36 -05:00
Doug Gregor
f267f62f65 [SILGen] Consistently use SIL asmname for foreign function/variable references
Whenever we have a reference to a foreign function/variable in SIL, use
a mangled name at the SIL level with the C name in the asmname
attribute. The expands the use of asmname to three kinds of cases that
it hadn't been used in yet:

* Declarations imported from C headers/modules
* @_cdecl @implementation of C headers/modules
* @_cdecl functions in general

Some code within the SIL pipeline makes assumptions that the C names of
various runtime functions are reflected at the SIL level. For example,
the linking of Embedded Swift runtime functions is done by-name, and
some of those names refer to C functions (like `swift_retain`) and
others refer to Swift functions that use `@_silgen_name` (like
`swift_getDefaultExecutor`). Extend the serialized module format to
include a table that maps from the asmname of functions/variables over
to their mangled names, so we can look up functions by asmname if we
want. These tables could also be used for checking for declarations
that conflict on their asmname in the future. Right now, we leave it
up to LLVM or the linker to do the checking.

`@_silgen_name` is not affected by these changes, nor should it be:
that hidden feature is specifically meant to affect the name at the
SIL level.

The vast majority of test changes are SIL tests where we had expected
to see the C/C++/Objective-C names in the tests for references to
foreign entities, and now we see Swift mangled names (ending in To).
The SIL declarations themselves will have a corresponding asmname.

Notably, the IRGen tests have *not* changed, because we generally the
same IR as before. It's only the modeling at the SIL lever that has
changed.

Another part of rdar://137014448.
2025-10-29 19:35:55 -07:00
Ramon Asuncion
83f7835339 [Test][multifile] Replace process substitution with file redirect 2025-10-15 14:09:02 -07:00
Dmitrii Galimzianov
091b005a60 Protocol conformance cache for generic types
This change adds a new type of cache (cache by type descriptor) to the protocol conformance lookup system. This optimization is beneficial for generic types, where the
same conformance can be reused across different instantiations of the generic type.

Key changes:
- Add a `GetOrInsertManyScope` class to `ConcurrentReadableHashMap` for performing
  multiple insertions under a single lock
- Add type descriptor-based caching for protocol conformances
- Add environment variables for controlling and debugging the conformance cache
- Add tests to verify the behavior of the conformance cache
- Fix for https://github.com/swiftlang/swift/issues/82889

The implementation is controlled by the `SWIFT_DEBUG_ENABLE_CACHE_PROTOCOL_CONFORMANCES_BY_TYPE_DESCRIPTOR`
environment variable, which is enabled by default.

This reapplies https://github.com/swiftlang/swift/pull/82818 after it's been reverted in https://github.com/swiftlang/swift/pull/83770.
2025-08-30 00:12:52 +02:00
Dmitrii Galimzianov
4509b22415 Revert "Protocol conformance cache for generic types"
This reverts commit 7989dbe24e merged in https://github.com/swiftlang/swift/pull/82818
2025-08-16 01:39:16 +02:00
Dmitrii Galimzianov
7989dbe24e Protocol conformance cache for generic types
This change adds a new type of cache (cache by type descriptor) to the protocol conformance lookup system. This optimization is beneficial for generic types, where the
same conformance can be reused across different instantiations of the generic type.

Key changes:
- Add a `GetOrInsertManyScope` class to `ConcurrentReadableHashMap` for performing
  multiple insertions under a single lock
- Add type descriptor-based caching for protocol conformances
- Add environment variables for controlling and debugging the conformance cache
- Add tests to verify the behavior of the conformance cache
- Fix for https://github.com/swiftlang/swift/issues/82889

The implementation is controlled by the `SWIFT_DEBUG_ENABLE_CACHE_PROTOCOL_CONFORMANCES_BY_TYPE_DESCRIPTOR`
environment variable, which is enabled by default.
2025-07-11 03:54:42 +02:00
Alex Hoppen
66104395d7 [Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
Some editors use diagnostics from SourceKit to replace build issues. This causes issues if the diagnostics from SourceKit are formatted differently than the build issues. Make sure they are rendered the same way, removing most uses of `DiagnosticsEditorMode`.

To do so, always emit the `add stubs for conformance` note (which previously was only emitted in editor mode) and remove all `; add <something>` suffixes from notes that state which requirements are missing.

rdar://129283608
2024-08-07 14:01:30 -07:00
Egor Zhdan
91bef8448a [IRGen] Upstream test changes for pointer authenticated value witness tables
The original change was done by Arnold Schwaighofer.
2024-07-02 18:35:12 +01:00
Alex Lorenz
0f9a69c712 android test fixes 2024-05-28 12:59:26 -07:00
Slava Pestov
af8c8f1671 Sema: Remove non-experimental associated type inference 2024-03-07 17:30:17 -05:00
Slava Pestov
35730d6bcf Sema: Don't be so eager to force type witnesses when resolving a value witness
resolveWitnessViaLookup() was only called from one place and didn't
need to force anything at all, and resolveSingleWitness() now only
forces the type witnesses actually referenced by the requirement.

An old crasher test case that was considered "fixed" when we started
to diagnose it now type checks correctly.
2024-01-26 18:51:08 -05:00
Slava Pestov
0b0ad738dd AST: Record a HadError bit in DelayedConformanceDiags 2024-01-20 19:16:58 -05:00
Michael Spencer
b2640e15e4 [test] Rename all module.map files to module.modulemap
`module.map` as a module map name has been discouraged since 2014, and
Clang will soon warn on its usage. This patch renames all instances of
`module.map` in the Swift tests to `module.modulemap` in preparation
for this change to Clang.

rdar://106123303
2023-08-21 15:58:59 -07:00
Nishith Shah
8e2e625543 [Diagnostics] Use imperative msg for protocol conformance & switch-case fixits
This commit changes fixit messages from a question/suggestion to an
imperative message for protocol conformances and switch-case. Addresses
https://github.com/apple/swift/issues/67510.
2023-08-13 22:34:26 -07:00
Becca Royal-Gordon
3732c75e97 Adopt %kind for certain access control diagnostics
These particular changes slightly alter some diagnostics.
2023-07-19 13:06:51 -07:00
Arnold Schwaighofer
b182b14e89 Try to fix test/multifile/nested_types.swift on windows 2023-06-24 15:31:06 -07:00
Arnold Schwaighofer
6962a3dc60 Fix test/multifile for opaque pointers 2023-06-23 06:57:38 -07:00
Arnold Schwaighofer
d1d7438a70 Move windows tests to %use_no_opaque_pointers usage 2023-06-14 10:49:50 -07:00
Arnold Schwaighofer
c1a93e0bde Move tests over to use the %use_no_opaque_pointers option 2023-06-14 10:49:48 -07:00
Anthony Latsis
1feed1dff0 Gardening: Migrate test suite to GH issues (file names): multifile 2022-09-18 19:07:45 +03:00
Anthony Latsis
4591933389 Gardening: Migrate test suite to GH issues: multifile 2022-09-01 06:44:42 +03:00
Ben Barham
c163e0fe5e [Tests] Make OS features consistent
lit.py currently allows any substring of `target_triple` to be used as a
feature in REQUIRES/UNSUPPORTED/XFAIL. This results in various forms of
the OS spread across the tests and is also somewhat confusing since they
aren't actually listed in the available features.

Modify all OS-related features to use the `OS=` version that Swift adds
instead. We can later remove `config.target_triple` so that these don't
the non-OS versions don't work in the first place.
2022-05-20 19:51:23 -07:00
Slava Pestov
dac8d666ee Stop passing -requirement-machine-{abstract,inferred,protocol}-signatures flags in tests
These flags are now no-ops.
2022-05-10 12:56:17 -04:00
Josh Soref
5e5f0b6d96 spelling: villain
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-05-01 00:16:05 -04:00
Josh Soref
c76ad9f0b6 spelling: offset
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-05-01 00:16:05 -04:00
Slava Pestov
8e09ba8b45 RequirementMachine: Introduce 'concrete contraction' pre-processing pass before building rewrite system
See the comment at the top of ConcreteContraction.cpp for a detailed explanation.

This can be turned off with the -disable-requirement-machine-concrete-contraction
pass, mostly meant for testing. A few tests now run with this pass both enabled
and disabled, to exercise code paths which are otherwise trivially avoided by
concrete contraction.

Fixes rdar://problem/88135912.
2022-02-25 11:48:38 -05:00
Slava Pestov
1050519db5 The Requirement Machine explicitly rejects the generic signature in protocol-conformance-rdar39805133.swift 2022-02-17 19:40:58 -05:00
Alastair Houghton
a0313e9538 [Runtime] Fix a potential NULL pointer dereference.
If we find multiple conformances for the same protocol, we generate a
warning.  This works fine for Swift types, but for Objective-C types
it's possible that while generating the warning we might find that the
type description is NULL.

Fix by using swift_getTypeName().

rdar://86368350
2022-01-21 17:42:02 +00:00
Evan Wilde
c18b50e96d Fixing flag truncations in llvm-readobj tests
It looks like commit 46580d43fc70d migrated the flags from llvm::cl to
OptTable. As a result, the flag behaviour changed. Commit
e29e30b1397f3e50f3487491f8a77ae08e4e3471 from 2019 went through and
changed the llvm tests to consistently use the double-dash for long
options so it was undetected.

With this info, I'm just going to go ahead and fix these tests cases to
get them going again.
2021-08-17 12:28:49 -07:00
Alastair Houghton
93c7d7876e [Tests] Fix redundant protocol conformance test for remote cases.
Apparently it's necessary to list all the files used in %target-run, otherwise
when we're running the tests remotely on a device, they might not be copied.

rdar://80283113
2021-07-13 12:16:18 +01:00
Alastair Houghton
c995942000 Add a test for redundant protocol conformance.
Added a test that builds two dynamic libraries and sets up a redundant protocol
conformance (we use dynamic libraries because the compiler will normally reject
redundant conformances), then checks that when we rely on it, we get a warning
message.
2021-06-18 10:06:20 +01:00
Robert Widmann
7c360ff1d8 Delete Flaky IR Hash Test
Our LLVM backend is supposed to have a build-time optimization where we
hash the IR and do not proceed with LLVM code generation if the hash
matches the one we last used to emit any products. This has never quite
worked for a variety of reasons - we fixed a number of those reasons in
https://github.com/apple/swift/pull/31106 but this test remained flaky
for its entire lifetime.

It's really not worth all the trouble to keep investigating this, so I'm
removing this test.

rdar://77654695
2021-05-12 10:02:48 -07:00
Arnold Schwaighofer
ed987685ee Disable batch-mode-llvmIRHash-consistency test
It fails multiple bots.

rdar://77654695
2021-05-07 06:46:38 -07:00
Robert Widmann
a4eed800e7 Re-Enable IR Hash Test
This was disabled due to timing issues on the bots. Now that everything
is on APFS/ext/NTFS, we should have the resolution necessary to turn
this back on.

rdar://62338337
2021-05-05 19:50:01 -07:00
Erik Eckstein
78ec15cf38 tests: remove some unused FileCheck prefix options
Such tests would fail with the -allow-unused-prefixes FileCheck option.

diff --git a/test/lit.cfg b/test/lit.cfg
-run_filecheck = '%s %s --sanitize BUILD_DIR=%s --sanitize SOURCE_DIR=%s --use-filecheck %s %s' % (
+run_filecheck = '%s %s --sanitize BUILD_DIR=%s --sanitize SOURCE_DIR=%s --use-filecheck %s %s -allow-unused-prefixes=false' % (

It helps avoiding some wrong CHECK patterns.
I just looked briefly at some of the fails. TODO: fix remaining tests, too.

rdar://74189761
2021-03-25 15:19:30 +01:00
Robert Widmann
eba9bbe36b Use the Formal Access *Scope* of the Extended Nominal For Its Max Access
Formal access alone does not take into account @testable imports of
internal types. This prevented otherwise valid conditional conformances
of these types from compiling.

rdar://72875683
2021-01-15 17:10:49 -08:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
Doug Gregor
6a40a3a8aa [SE-0289] Add support for @resultBuilder.
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
2020-10-20 13:24:51 -07:00
Slava Pestov
ab83d907ac Sema: Fix cycle between closure type computation and EmittedMembersRequest
EmittedMembersRequest needs a stable order for synthesized members
to ensure that vtable layout is computed consistently across frontend
jobs. This used to use the mangled name as the sort key.

However, the mangling includes the type of all outer contexts, and if
an outer type is a closure, we would need to compute the type of the
closure. Computing the type of a closure might require type checking
its body though, which would in turn type check the local class, which
would invoke EmittedMembersRequest, introducing a cycle.

Instead, let's use the DeclName and string-ified type as the sort key.
This is simpler to compute than th mangled name, and breaks the cycle.

Fixes <rdar://problem/67842221>.
2020-09-01 18:30:25 -04:00
David Zarzycki
97c89d8d3a Remove three ObjC fields from non-ObjC runtime 2020-05-22 09:21:21 -07:00
Arnold Schwaighofer
cc8ecf414f Disable test batch-mode-llvmIRHash-consistency
It fails in some configurations.

rdar://62338337
2020-05-06 11:24:42 -07:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Mishal Shah
00612d74bb Update the batch-mode-llvmIRHash-consistency test to use echo method for updating the timestamp 2020-04-23 14:59:03 -07:00
Mishal Shah
b6927d17ac Fix the path to make-old.py 2020-04-21 23:47:53 -07:00
Mishal Shah
7a9e8bf12b [Test] Update batch-mode-llvmIRHash-consistency.swift to use make-old.py to avoid touch issue 2020-04-21 23:06:01 -07:00
David Ungar
9dcd2b52b2 Allocate LLVMContext in IRGenModule. 2020-04-16 11:57:44 -07:00
Slava Pestov
8ee5d2931f Sema: Force property wrappers in EmittedMembersRequest::evaluate()
Fixes <rdar://problem/61229365>.
2020-04-09 19:57:12 -04:00
Slava Pestov
52c11c78d1 Sema: Property wrapper storage wrappers ($foo) inherit 'final' bit from original property
Otherwise, we would generate inconsistent vtable layouts for classes
with static properties that have attached wrappers. The reason is that
we normally force synthesis of the backing storage and storage wrapper
for each instance property wrapper as part of computing the lowered
stored properties.

However, there was no such forcing for static properties. But since a
static stored property (with an attached wrapper or otherwise) must be
'final', the real fix is to just ensure that the 'final' bit propagates
to the storage wrapper as well.

The backing storage property was already always final, so the issue
did not arise there.

Fixes <rdar://problem/59522703>, <https://bugs.swift.org/browse/SR-12429>.
2020-03-31 23:42:34 -04:00