Commit Graph

143 Commits

Author SHA1 Message Date
Robert Widmann
518ab9f22f [NFC] Unblock Lazy Member Loading For Import-As-Member
Lazy member loading had an antagonistic relationship with the import-as-member facilities. The member tables were stored in a hash map that is keyed by serialized declaration context.  While this was good for importing the entire member set of a given extension, it's in the complete wrong order for lazy member loading, which wants the same data keyed by base name.

Given that it is annoying to redo the globals-as-member tables to support one use case or the other, coupled with the fact that optimizing for one use-case automatically pessimizes the other, just take a page from rdar://18696086 and store the same information twice in two separate formats each optimized for the task at hand.

Preliminary benchmarks indicate that this leads to a 5% reduction in Clang-Imported entities which will drastically speed up most apps that use Dispatch and CoreGraphics.
2020-01-08 21:25:00 -08:00
Francis Visoiu Mistrih
47c6ce2af7 [Bitcode] Update includes: llvm/Bitcode -> llvm/Bitstream
The Bitstream part of Bitcode moved to llvm/Bitstream in LLVM. This
updates the uses in swift.

See r365091 [Bitcode] Move Bitstream to a separate library.

(cherry picked from commit 1cd8e19357)
2019-11-12 10:46:07 -08:00
JF Bastien
e56e311a23 Fix Swift following bitstream reader API update (#25845)
* Fix Swift following bitstream reader API update

Upstream change in rL364464 broke downstream Swift.

(cherry picked from commit 50de105bf1)

 Conflicts:
	lib/Serialization/Deserialization.cpp
	lib/Serialization/ModuleFile.cpp
	tools/driver/modulewrap_main.cpp
2019-11-12 10:46:07 -08:00
swift-ci
0b41d02a4d Merge remote-tracking branch 'origin/master' into master-next 2019-10-31 20:49:50 -07:00
Brent Royal-Gordon
17169fc1fe Merge pull request #27950 from brentdax/dumpster-fire
[NFC] Standardize dump() methods in frontend
2019-10-31 20:36:26 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Saleem Abdulrasool
1955746c6f ClangImporter: repair a merge conflict
`llvm::make_unique` has been replaced with `std::make_unique`.  Adjust
the master-next branch accordingly.
2019-10-30 10:04:23 -07:00
swift-ci
89318956f7 Merge remote-tracking branch 'origin/master' into master-next 2019-10-30 09:10:41 -07:00
Jordan Rose
8168669a27 [ClangImporter] Diagnose bad swift_name attributes better
1. Set the diagnostic location to where the attribute was written (or
   to the Clang decl's source, if the attribute came from API notes)

2. Add a note to contact the owners of the framework to make it clear
   that the client of the framework didn't do anything wrong.

rdar://problem/52736145
2019-10-28 22:08:26 -07:00
swift-ci
bd3c1a1b9f Merge remote-tracking branch 'origin/master' into master-next 2019-08-29 14:29:44 -07:00
Jordan Rose
11e206af7a Remove explicit seeds from string hashes that are compiler-dependent
The one for enum raw value checking isn't serialized anywhere, so we
can use normal in-process hashing. The ones in the Clang importer's
lookup tables are serialized, but the lookup table is already only
valid for a particular compiler build anyway (it goes into a Clang
PCM, which has the full compiler version in its cache key).
2019-08-29 09:19:49 -07:00
Jonas Devlieghere
b4d268e9e1 Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
2019-08-15 11:32:39 -07:00
Pavel Yaskevich
3d01a3d723 Merge remote-tracking branch 'origin/master' into master-next 2019-08-02 09:57:06 -07:00
pschuh
2a2ed0f843 [C++ Interop] Implement lookup within namespace. (#26439)
Known problems:
- The same namespace in multiple c++ modules will be subtly confused when doing
  lookup.
2019-08-01 18:21:08 -07:00
swift-ci
9894743d4f Merge remote-tracking branch 'origin/master' into master-next 2019-07-09 11:50:28 -07:00
Parker Schuh
fa69a73ee4 Add -enable-cxx-interop flag and support for extern "C" {} 2019-07-08 11:43:35 -07:00
Francis Visoiu Mistrih
1cd8e19357 [Bitcode] Update includes: llvm/Bitcode -> llvm/Bitstream
The Bitstream part of Bitcode moved to llvm/Bitstream in LLVM. This
updates the uses in swift.

See r365091 [Bitcode] Move Bitstream to a separate library.
2019-07-03 15:40:03 -07:00
JF Bastien
50de105bf1 Fix Swift following bitstream reader API update (#25845)
* Fix Swift following bitstream reader API update

Upstream change in rL364464 broke downstream Swift.
2019-07-01 10:08:41 -07:00
Jordan Rose
e75c035772 [ClangImporter] Clean up some casts/deletes using forward declarations (#19367)
No functionality change.
2018-09-18 10:34:50 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Robert Widmann
014fd952ef [NFC] Silence a bunch of Wunused-variable diagnostics 2018-08-24 15:16:40 -07:00
swift-ci
4a1824018d Merge remote-tracking branch 'origin/master' into master-next 2018-06-21 11:49:28 -07:00
Jordan Rose
26325e8301 [ClangImporter] Put the Swift compiler version into the module hash (#17344)
This is overkill when we could just be better about updating the
lookup table version, but it's hard to remember to do that when
changing something in ImportName.cpp or whatever.
2018-06-21 11:40:16 -07:00
swift-ci
2a0e83dc0d Merge remote-tracking branch 'origin/master' into master-next 2018-06-18 11:00:19 -07:00
Jordan Rose
864bf89f69 [ClangImporter] Handle lookup tables with many entries (#17265)
In particular, there are frameworks with more than 65536 entries for
'init' as a base name.

I can't think of a test case for this besides actually adding such a
massive framework, but the assertions that were added here should
catch the issue in Debug builds if it ever comes up again. I'm going
to go harden everything else that uses this API next.

rdar://problem/40828315
2018-06-18 08:39:55 -07:00
Bob Wilson
d933b5d60c Merge remote-tracking branch 'origin/master' into master-next 2018-06-15 20:20:25 -07:00
Jordan Rose
570ed72ea5 Add assertions to prevent truncation when using llvm::endian::Writer (#17266)
Also, stop serializing a few constant values, saving a tiny bit of
space in swiftmodule files.
2018-06-15 19:26:35 -07:00
swift-ci
7fff7b3ddf Merge remote-tracking branch 'origin/master' into master-next 2018-05-21 21:49:25 -07:00
Rintaro Ishizaki
b3453c17fe [ClangImporter] Take isCompatibilityAlias() into account in interface printing (#16625)
If the Clang declrations are *types*, canonical declaration in Swift is
imported for newest version of Swift. In interface generation, if the
declaration is versioned and it's imported as a member in either or both
version of Swift, we have to take compatibility typealias into account.

* Fixed 'ClangModuleUnit::getTopLevelDecls' to take isCompatibilityAlias() into account
* Fixed bugs in ClangImporter where member-to-member versioned types aren't properly imported.
  * Fixed 'SwiftDeclConverter::importFullName' to check equality of getEffectiveContext()
  * Fixed 'importer::addEntryToLookupTable' to check equality of getEffectiveContext()
    (moved 'ClangImporter::Implementation::forEachDistinctName' to 'NameImporter')
2018-05-22 13:38:45 +09:00
Bob Wilson
1fc7f1391e [master-next] Update endian stream interface to match Clang r332757 2018-05-19 22:19:35 -07:00
swift-ci
cb7f139ad1 Merge remote-tracking branch 'origin/master' into master-next 2018-04-03 13:39:21 -07:00
Doug Gregor
24b96a7480 Delay import-as-member resolution even without an explicit swift_name.
When forming the Swift name lookup tables, import-as-member'd
declarations can precede the declaration of the context into which
they'll be imported as a member. In such cases, we already had logic
to delay the resolution until the end of the model (when the context
must be complete).

However, we would only delay when there is a swift_name attribute on
the declaration, which is... conceptually correct. If the swift_name
exists but is versioned (e.g., it is present only for Swift 4+), and
we're building before the swift_name took effect (e.g., in Swift 3
mode), the swift_name is buried under a "versioned" attribute in the
Clang AST. Therefore, we would end up dropping the declaration from
the name lookup table, which almost doesn't matter, except...

Serialization records the newest names for such declarations (e.g.,
Swift 4+ name in this case), so deserialization would fail to find the
declaration that had been dropped, causing a crash.

Eliminate the "optimization" that looks for the swift_name attribute
before delaying the resolution of such a declaration, so we'll visit
these later. Fixes rdar://problem/39115605.
2018-04-03 11:26:05 -07:00
swift-ci
d80ce649ed Merge remote-tracking branch 'origin/master' into master-next 2018-03-16 03:09:03 -07:00
Slava Pestov
30dae65226 AST: Add DeclBaseName::Kind::Constructor
Not used yet.
2018-03-16 00:25:54 -07:00
Adrian Prantl
0747d9a339 Force the DJB hash seed to 0 for compatibility with HashString.
The obsolete llvm::HashString() was equivalent to
llvm::djbHash(seed=0) and was removed from llvm. This patch replaces
all occurences of llvm::HashString() with llvm::djbHash(seed=0), no
functional change.

The default seed of llvm::djbHash() is supposed to yield a higher
quality result that using seed=0, but changing it looks like it
affects the ordering of SIL serialization.
2018-02-28 14:10:25 -08:00
Saleem Abdulrasool
a0c6a70c31 upstream-update: adjust for SVN r326091 2018-02-27 12:36:15 -08:00
Jordan Rose
b53967fd19 [ClangImporter] Handle macros that are undefined and then redefined (#12413)
This includes 'LONG_MAX' in the Darwin module, which is defined by the
system and then immediately redefined by Clang's copy of limits.h.

The general strategy here is that if two definitions of a macro in the
same module are in separate explicit submodules, we need to keep track
of both of them, but if they're in the same explicit submodule then
one is probably deliberately redefining the other. This isn't fully
correct because one explicit submodule could include another explicit
submodule, but it's a good first approximation, which we can refine if
we come across problem cases in practice.

Swift /also/ has the ability to distinguish between ModuleA.MACRO and
ModuleB.MACRO if you've imported both modules, although there's an
issue that the two of them end up getting the same mangled name if you
try to use both in the same compilation unit. (Filed
rdar://problem/34968281.) That ability is preserved with this change.

All of this will likely change if/when we switch to Clang's "local
submodule visibility" mode, which is needed for the C++ Modules TS but
is also incompatible with Apple's SDKs at the moment. In that case,
macros in two separate explicit submodules will no longer have an
'override' relationship just because they're mentioned sequentially in
the module map.

rdar://problem/34413934
2017-10-13 15:08:51 -07:00
Jordan Rose
9a04bee421 [ClangImporter] Turn ImportNameVersion into a struct.
...so that we don't have to keep coming back to update it every major
release. And also so we can actually put methods on it instead of
using free functions.

No intended behavior change (yet).
2017-09-15 14:30:24 -07:00
Jordan Rose
a009cc583c [ClangImporter] Ignore VisibilityMacroDirectives in the lookup tables (#11393)
In theory, Clang's module system supports the notion of "public" and
"private" macros in a framework, currently implemented by the
supported feature at this point, but we do make sure the Swift
compiler can handle them.

However, visibility directives for built-in macros would end up
showing up in the list of defined macros that we iterate over to write
out the Swift name lookup tables for a module. Since we pack
ModuleMacro and MacroInfo pointers into the same data structure
/without/ a discriminator bit, this led to a nonsense reinterpret_cast
later on. This manifested as rare test failures later.

Bail out in this case, and assert in NDEBUG builds that it's actually
this case and not some other problematic case that we haven't
encountered yet.

I'm not filing a bug for real support of the macro visibility
directives because it wouldn't be prioritized until there's a
real-world test case anyway (sad realities of compiler development).

rdar://problem/33745657
2017-08-08 19:22:08 -07:00
swift-ci
e506bb3134 Merge remote-tracking branch 'origin/master' into master-next 2017-08-01 08:08:52 -07:00
Alex Hoppen
2eb36e41f5 Introduce special name for destructors
This name is not used yet
2017-07-28 10:46:50 +02:00
Jordan Rose
beb4305986 [ClangImporter] Simplify the macro logic from the previous commit.
No functionality change.
2017-07-26 15:42:31 -07:00
Jordan Rose
5d053d95a4 [ClangImporter] Restore proper macro shadowing rules.
Last follow-up to c3d6be64ab. Already covered by
test/ClangImporter/macros_redef.swift.

rdar://problem/32199805
2017-07-26 15:42:31 -07:00
swift-ci
e0782d0448 Merge remote-tracking branch 'origin/master' into master-next 2017-07-11 13:29:16 -07:00
Alex Hoppen
f8c2692f79 Introduce special decl names
Special DeclNames represent names that do not have an identifier in the
surface language. This implies serializing the information about whether
a name is special together with its identifier (if it is not special)
in both the module file and the swift lookup table.
2017-07-11 19:04:13 +02:00
Jordan Rose
c3d6be64ab WIP Update to use clang::ModuleMacro instead of clang::MacroInfo.
Untested and still missing a few pieces.
2017-06-23 16:04:24 -07:00
Jordan Rose
c0ccdb1626 Change getBaseName to return DeclBaseName instead of Identifier (#9968)
This changes `getBaseName()` on `DeclName` to return a `DeclBaseName`
instead of an `Identifier`. All places that will continue to be
expecting an `Identifier` are changed to call `getBaseIdentifier` which
will later assert that the `DeclName` is actually backed by an
identifier and not a special name.

For transitional purposes, a conversion operator from `DeclBaseName` to
`Identifier` has been added that will be removed again once migration
to DeclBaseName has been completed in other parts of the compiler.

Unify approach to printing declaration names

Printing a declaration's name using `<<` and `getBaseName()` is be
independent of the return type of `getBaseName()` which will change in
the future from `Identifier` to `DeclBaseName`
2017-05-28 17:55:03 -07:00
Jordan Rose
837a180f0a [ClangImporter] Import-as-member support for anonymous enum constants. (#9633)
Previously this (1) did not work (the constant just disappeared), and
(2) would actually crash if the destination context was a class.

rdar://problem/32208235
2017-05-16 11:57:49 -07:00
Jordan Rose
c9124d989d [ClangImporter] Import Swift 3 versions of top-level decls in Swift 4.
...and Swift 4 versions in Swift 3, and Swift 2 and "raw" versions in
both. This allows the compiler to produce sensible errors and fix-its
when someone uses the "wrong" name for an API. The diagnostics
certainly have room to improve, but at least the essentials are there.

Note that this commit only addresses /top-level/ decls, i.e. those
found by lookup into a module. We're still limited to producing all
members of a nominal type up front, so that'll require a slightly
different approach.

Part of rdar://problem/29170671
2017-02-24 14:01:10 -08:00
Jordan Rose
a5da848064 [ClangImporter] Put all versions of names into the lookup table.
The compiler uses the non-active names to import unavailable
declarations telling the user the correct name. Right now it's still
only importing "Swift 2" and "current", but that should change.

For reference, the best example of a declaration that has four names
is a factory method with a custom NS_SWIFT_NAME annotation:

- Its raw name is the plain Objective-C name, written as a method:
  'fooByFrobnicatingBar(_:)'.
- Its "Swift 2" name is the Swift-2-style translation of that to an
  initializer: 'init(byFrobnicatingBar:)'
- Its "Swift 3" name applies the "omit needless words" transformation:
  'init(frobnicating:)'.
- Its "Swift 4" name uses the name specified by NS_SWIFT_NAME.
2017-02-24 13:26:21 -08:00