Commit Graph

28 Commits

Author SHA1 Message Date
susmonteiro
585ca5e2da [cxx-interop] Adding swift_name attributes to virtual methods overrides 2025-07-17 16:23:32 +01:00
Becca Royal-Gordon
54fd4b01b6 Add workaround flag for lazy import-as-member
In rdar://123649082, a project failed to build because of the lazy import-as-member loading changes in #71320. That project was configured in a way that broke modularization and the correct solution is to fix it, but out of an abundance of caution, add a `-disable-named-lazy-import-as-member-loading` frontend flag in case a project needs to temporarily restore the old behavior.

As a bonus, this lets us write a test to verify that lazy import-as-member loading has positive performance impact.
2024-03-05 11:09:17 -08:00
Becca Royal-Gordon
1a97803c8c Add flag for dumping ClangImporter lookup tables
ClangImporter’s SwiftLookupTables map Swift names to their corresponding Clang declarations. These tables are built into a module’s clang .pcm file and missing or inaccurate entries can cause name lookup to fail to find an imported declaration.

Swift has always included a helper function that would dump these tables, and swift-ide-test has a command-line switch that would invoke it, but these tools are clumsy to use in many debugging scenarios. Add a frontend flag that dumps the tables at the end of the frontend job, making it a lot easier to get at this information in the context of a specific compilation.
2024-02-29 17:51:00 -08:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Doug Gregor
55a3f5398c [Clang importer] Import Swift 2 "stubs" to improve errors in "Swift 2" code.
When attempting to compile Swift 2 code (or any Swift code using the
Swift 2 names) in Swift 3, the compiler diagnostics are often entirely
useless because the names have changed radically enough that one
generally gets "no member named 'foo'" errors rather than a helpful
"'foo' was renamed to 'bar'" error. This makes for a very poor user
experience when (e.g.) trying to move Swift 2 code forward to Swift 3.

To improve the experience, when the Swift 2 and Swift 3 names of an
API differ, the Clang importer will produce a "stub" declaration that
matches the Swift 2 API. That stub will be marked with a synthesized
attribute

  @available(unavailable, renamed: "the-swift-3-name")

that enables better diagnostics (e.g., "'foo' is unavailable: renamed
to 'bar') along with Fix-Its (courtesy of @jrose-apple's recent work)
that fix the Swift 2 code to compile in Swift 3.

This change addresses much of rdar://problem/25309323 (concerning QoI
of Swift 2 code compiled with a Swift 3 compiler), but some cleanup
remains.
2016-05-06 21:12:20 -07:00
Michael Ilseman
b46c1deb6a [Import as member] Fix up test cases 2016-04-11 13:40:44 -07:00
Michael Ilseman
d7581d1b36 Merge commit 'a31edf53d0580efe47f4e9ef89dccc4429c056e8' into import-as-member 2016-03-23 13:05:57 -07:00
Joe Groff
c4a69e9d5d SILGen: Basic code generation for C functions imported as methods.
Introduce abstraction patterns for curried C-functions-as-methods for type lowering, and plumb the "foreign self parameter index" through call emission so that we emit the "self" parameter in the right position. This gets us handling C functions imported as methods with explicit swift_name attributes in simple, fully-applied cases. There's still more work to be done for properties, partial applications, and initializers introduced by extensions.
2016-03-17 10:43:25 -07:00
Doug Gregor
b775b4af91 [Clang importer] Update expected output for name lookup table dump. 2016-03-07 20:57:34 -08:00
Max Moiseev
cf4bafe9e3 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-03 13:22:03 -08:00
Doug Gregor
f7ee0349ea [Clang importer] (De-)serialize globals-as-members for Swift name lookup tables.
Round-trip the globals-as-members table used by the Swift name lookup
tables. At present, there are no clients of this information except
the dumper.
2016-03-01 18:13:35 -08:00
Doug Gregor
8649fa440a [Clang importer] Record globals imported as members in Swift name lookup tables.
Whenever we add an entry that corresponds to a global Clang entity
that will be imported as a member, where that member structure isn't
inherently encoded in Clang, separately record it as being a member of
the context in a separate table. Verify that we're getting the entries
we expect in this table.
2016-03-01 17:01:30 -08:00
Doug Gregor
3ffbe020d7 [Clang importer] Handle name mapping for "getter:" and "setter:" in swift_name.
The swift_name string format now supports "getter:" and "setter:"
prefixes to indicate that a function is the getter or setter of a
Swift-synthesized property. Start parsing these DeclNames and make
sure they're reflected in the Swift name lookup tables.

[Clang update required]
2016-03-01 15:33:21 -08:00
Doug Gregor
7265328e07 [Clang importer] Generalize name lookup tables for globals-as-members.
A swift_name attribute on a global declaration can specify a dotted
name (e.g., SomeStruct.member) to map that global into a member of the
(Swift-)named type. Handle this mapping in DeclName parsing, plumb it
through importFullName, and cope with it in the Swift name lookup
tables (tested via the dump) and importing into a Swift DeclContext
(as-yet-untested). Part of SE-0033.
2016-03-01 15:33:20 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Doug Gregor
06d25f7151 Update test cases now that we're filtering macros properly. 2016-02-03 20:08:31 -08:00
Doug Gregor
908e2ac721 Clang importer: Make sure we're building Swift lookup tables for the bridging header. 2015-12-17 07:11:48 -08:00
Doug Gregor
f8a76d10c0 Clang importer: add macros to the Swift name lookup tables.
Refactor the storage within the name lookup tables to handle
declarations and macros together. Start populating the tables with
macro information.
2015-12-08 22:56:28 -08:00
Doug Gregor
86701de88a Clang importer: (de-)serialize Swift name lookup tables via module file extensions.
The recently-introduced module file extensions functionality in Clang
allows us to piggy-back the Swift name lookup tables in Clang's module
files. When the Swift name lookup tables are enabled, introduce such a
module file extension, and wire it into the SwiftLookupTable.

The actual contents of the extension block are simple: a single
on-disk hash table mapping base names to "full entries", which store
the context (e.g., a class, protocol, tag, or TU) and the set of
declarations.

Allow lazy resolution of declaration IDs deserialized from the
extension block to Clang declarations, to try to minimize the set of
declarations we must deserialize. Name lookup itself is only used to
dump the Swift name lookup tables and ensure we're round-tripping
properly.
2015-12-08 17:34:04 -08:00
Doug Gregor
f40b195a73 Clang importer: simplify Swift name lookup tables a bit.
The base name -> full name mapping really isn't interesting; index
based on the base name and filter by context instead. This makes the
lookup table dumper less interesting for testing purposes
(unfortunately), but test coverage will improve greatly once we can
turn on these lookup tables.
2015-12-08 17:34:04 -08:00
Doug Gregor
907fa0b70c Linux: Mark this test as requiring Objective-C interop for now.
I believe we should be able to handle the enum mapping without
Objective-C interoperability, but something in the Clang importer
doesn't seem to be doing this correctly now.
2015-12-03 15:30:51 -08:00
Doug Gregor
fa865c7165 Clang importer: handle enumerator prefix stripping in importFullName().
Centralize the mapping of C names to Swift names further by including
enumerator prefix stripping, rather than having that as a separate
path. The actual logic and code for computing the prefix is unchanged
(despite moving from one file to another). This corrects the name
computed for the Swift lookup tables, but is an NFC refactoring for
everything else.

With this, kill off importName(), because it's been entirely
superseded by importFullName().
2015-12-03 11:50:40 -08:00
Doug Gregor
c41535a7fb Clang importer: start computing the effective lookup context with the name.
This places enumerators that will become either cases of a Swift enum
or options in a Swift option into the context of the C enum type for
the name lookup table.
2015-12-03 11:50:40 -08:00
Doug Gregor
28dea3bc27 Clang importer: recursively add members to the Swift lookup tables.
This is needed for member lookup via the Swift lookup tables, although
the lookup part is not yet implemented. Note also that the results are
currently wrong for C enumerations mapped into Swift enums or option
sets. That will come shortly.
2015-12-03 11:50:40 -08:00
Doug Gregor
2dc262f5b0 Clang importer: Don't add duplicate declarations to the Swift lookup tables. 2015-12-03 11:50:40 -08:00
Doug Gregor
f798d53f92 Clang importer: convert more importName callers over to importFullName. NFC
The sole remaining caller to importName is for enumerators, which may
have prefixes that need stripping. That refactor will come in a
subsequent commit.
2015-12-03 11:50:40 -08:00
Doug Gregor
a861a7345e Clang importer: introduce "importFullName" to centralize name-mapping logic.
The Swift lookup tables are the primary client and test vehicle right
now. This change adds the capability to use the swift_name attribute
to rename C functions when they are imported into Swift, as well as
handling the swift_private attribute more uniformly.

There are a few obvious places where I've applied this API to
eliminate redundancy. Expect it to broaden as the API fills out more.
2015-12-03 11:50:39 -08:00
Doug Gregor
c2bf16c0a9 Clang importer: start building a Swift name -> Clang declarations table.
When we parse a bridging header, start building a mapping from Swift
names (both base names and full names) to the Clang declarations that
have those names in particular Clang contexts. For now, just provide
the ability to build the table (barely) and dump it out; we'll grow
it's contents in time.
2015-12-03 11:50:39 -08:00