Commit Graph

198 Commits

Author SHA1 Message Date
Dan Zheng
165af547f3 Fix SynthesizedFileUnit serialization and TBDGen issues.
Make `SynthesizedFileUnit` attached to a `SourceFile`. This seemed like the
least ad-hoc approach to avoid doing unnecessary work for other `FileUnit`s.

TBDGen: when visiting a `SourceFile`, also visit its `SynthesizedFileUnit` if
it exists.

Serialization: do not treat `SynthesizedFileUnit` declarations as xrefs when
serializing the companion `SourceFile`.

Resolves TF-1239: AutoDiff test failures.
2020-04-08 21:19:56 -07:00
marcrasi
eefe9a083c Merge pull request #30851 from apple/derivative-attr-serialization
[AutoDiff] SR-12526: cross-module @derivative deserialization
2020-04-07 17:23:47 -07:00
Dan Zheng
83f6714334 [AutoDiff] Start fixing SR-12526.
Start fixing SR-12526: `@derivative` attribute cross-module deserialization
crash. Remove original `AbstractFunctionDecl *` from `DerivativeAttr` and store
`DeclID` instead, mimicking `DynamicReplacementAttr`.
2020-04-06 06:37:23 -07:00
Cyndy Ishida
6a29923c5e [TBDGen] update tbd version
Short overview of new TBD-v4 format changes:

* special section for reexported symbols (which is not seen any
differently to the linker)

* target based slices as opposed to just architecture

more information in: rdar://problem/60586390
2020-04-03 20:38:15 -07:00
Dan Zheng
4671dc5c0f [AutoDiff upstream] Add TBDGen for AutoDiff symbols.
Emit symbols for `@differentiable` and `@derivative` declaration attributes:
- Differentiability witness symbols.
- Derivative function (JVP/VJP) symbols.
- Linear map (differential/pullback) symbols.

Add TBDGen test.
2020-04-03 01:14:28 +00:00
Suyash Srijan
f724d1ff85 [SE-0280] Enum cases as protocol witnesses (#28916)
* [Typechecker] Allow enum cases without payload to witness a static get-only property with Self type protocol requirement

* [SIL] Add support for payload cases as well

* [SILGen] Clean up comment

* [Typechecker] Re-enable some previously disabled witness matching code

Also properly handle the matching in some cases

* [Test] Update typechecker tests with payload enum test cases

* [Test] Update SILGen test

* [SIL] Add two FIXME's to address soon

* [SIL] Emit the enum case constructor unconditionally when an enum case is used as a witness

Also, tweak SILDeclRef::getLinkage to update the 'limit' to 'OnDemand' if we have an enum declaration

* [SILGen] Properly handle a enum witness in addMethodImplementation

Also remove a FIXME and code added to workaround the original bug

* [TBDGen] Handle enum case witness

* [Typechecker] Fix conflicts

* [Test] Fix tests

* [AST] Fix indentation in diagnostics def file
2020-03-28 10:44:01 +00:00
Robert Widmann
1f904ca86d Merge pull request #30669 from CodaFi/consteval
[NFC] A Handful of Sweeping Evaluator Cleanups
2020-03-27 09:43:28 -07:00
Robert Widmann
987cd55f50 [NFC] Drop llvm::Expected from Evaluation Points
A request is intended to be a pure function of its inputs. That function could, in theory, fail. In practice, there were basically no requests taking advantage of this ability - the few that were using it to explicitly detect cycles can just return reasonable defaults instead of forwarding the error on up the stack.

This is because cycles are checked by *the Evaluator*, and are unwound by the Evaluator.

Therefore, restore the idea that the evaluate functions are themselves pure, but keep the idea that *evaluation* of those requests may fail. This model enables the best of both worlds: we not only keep the evaluator flexible enough to handle future use cases like cancellation and diagnostic invalidation, but also request-based dependencies using the values computed at the evaluation points. These aforementioned use cases would use the llvm::Expected interface and the regular evaluation-point interface respectively.
2020-03-26 23:08:02 -07:00
Xi Ge
31afb3f692 Revert "TBDGen: avoid emitting symbols with OBJC_CLASS and OBJC_METACLASS prefixes"
For clang decls marked with SWIFT_CLASS, these explicit class initializer symbols turn
out to be necessary in the TBD files.

rdar://60857470
2020-03-26 10:46:53 -07:00
Slava Pestov
9ec80df97e SIL: Remove curried SILDeclRefs 2020-03-19 02:20:21 -04:00
Dmitri Gribenko
841eeb05b0 Merge pull request #30403 from MForster/forster/string-fixes
Cherry-pick StringRef->std::string conversion fixes into `master`
2020-03-17 12:09:36 +01:00
Xi Ge
251edf3765 TBDGen: don't emit $ld$previous$ symbols for added members to a moved decl
When a top-level decl is marked with @_originallyDefinedIn, some of its members
may also be newly added after the top-level decl has been moved to the current module.
For these members, we don't need emit $ld$previous$ symbols for them.

rdar://60478650
2020-03-15 19:02:31 -07:00
Xi Ge
1fc0799e8b TBDGen: omit witness table symbol for imported resilient protocols
For imported resilient protocols, we cannot directly emit witness table
symbol when a local type conforms to them because initializing these
protocols are required.

rdar://60429448
2020-03-13 13:46:50 -07:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Xi Ge
699e05712f TBDGen: avoid emitting symbols with OBJC_CLASS and OBJC_METACLASS prefixes
rdar://60057489
2020-03-06 16:07:57 -08:00
Xi Ge
2f5f66b9da Re-apply "TBDGen: pass-down target variant when generating textual interface stubs"
rdar://60057760
2020-03-05 11:00:14 -08:00
Rintaro Ishizaki
58d4868e42 Revert "TBDGen: pass-down target variant when generating textual interface stubs" 2020-03-04 22:01:24 -08:00
Xi Ge
6dde0e6abc TBDGen: pass-down target variant when generating textual interface stubs
rdar://60057760
2020-03-04 15:52:29 -08:00
Hamish Knight
586e586af2 Add top-level request for TBDGen
Introduce `GenerateTBDRequest` which outputs the
interface file along with a set of public symbols.
2020-02-13 21:52:45 -08:00
Hamish Knight
4867c5fc93 NFC: Remove unused member from UniversalLinkageInfo 2020-02-13 20:44:38 -08:00
Xi Ge
e013f1fb81 TBDGen: add a flag for embedding external symbols in emitted tbd file
Static-linked libraries could add symbols to the final tbd file. We need
this flag to specify additional module names to collect symbols from.

rdar://59399684
2020-02-12 13:47:59 -08:00
Devin Coughlin
082421048a [AST/Sema] Add availability attributes for macCatalyst
Add a platform kind and availability attributes for macCatalyst. macCatalyst
uses iOS version numbers and inherits availability from iOS attributes unless
a macCatalyst attribute is explicitly provided.
2020-01-21 20:27:14 -08:00
Xi Ge
3ee9b1175c TBDGen: when previous install name map is specified, emit $ld$previous linker directives.
Progress towards: rdar://58281536
2020-01-17 15:57:25 -08:00
Xi Ge
caf88fb1eb TBDGen: some refactoring to allow multiple platform kinds for linker directives.
Tentatively fixing: rdar://58569201
2020-01-16 11:42:03 -08:00
Xi Ge
90f59e4336 TBDGen: teach the compiler to take a json file indicating previous install names
Using the new linker directives $ld$previous requires the compiler to know the previous
install names for the symbols marked as removed. This patch teaches the compiler
to take a path to a Json file specifying the map between module names and previous
install names. Also, these install names can be platform-specific.

Progress towards: rdar://58281536
2020-01-13 17:45:40 -08:00
Xi Ge
66b4737ddc TBDGen: use active platform versions to genearate linker directives 2019-12-12 22:22:28 -08:00
Xi Ge
93a83d3f14 IRGen: reuse linker directives collected from tbd gen to emit these symbols to IR 2019-12-12 22:22:28 -08:00
Xi Ge
c484894668 TBDGen: generate $ld$hide$os symbols for decls marked with @_originallyDefinedIn
Combined with @available attribute, we could infer the OS versions that a particular
symbol doesn't exist in the current framework (LowLevel framework). For these OS versions,
we need to emit $ld$hide directives to avoid the LowLevel framework to be linked against.

Need this for rdar://55268186
2019-12-12 22:22:28 -08:00
Robert Widmann
4e36fc0bd5 Replace semantic usages of DynamicReplacementAttr with the request
Complete the refactoring by splitting the semantic callers for the original decl of a dynamically replaced declaration.

There's also a change to the way this attribute is validated and placed.  The old model visited the attribute on any functions and variable declarations it encountered in the primary.  Once there, it would strip the attribute off of variables and attach the corresponding attribute to each parsed accessor, then perform some additional ObjC-related validation.

The new approach instead leaves the attribute alone.  The request exists specifically to perform the lookups and type matching required to find replaced decls, and the attribute visitor no longer needs to worry about revisiting decls it has just grafted attributes onto.  This also means that a bunch of parts of IRGen and SILGen that needed to fan out to the accessors to ask for the @_dynamicReplacement attribute to undo the work the type checker had done can just look at the storage itself.  Further, syntactic requests for the attribute will now consistently succeed, where before they would fail dependending on whether or not the type checker had run - which was generally not an issue by the time we hit SIL.
2019-12-03 15:30:04 -08:00
Harlan Haskins
3745dcc3e4 [TBDGen] Match TAPI's truncation behavior for dylib versions
TAPI and the linker truncate individual version components to 255 if
they overflow, because the linker packs 3 version components into a
32-bit int. Make sure we use the same parsing routines as TAPI.

Fixes rdar://57043178
2019-11-11 15:11:19 -08:00
Cyndy Ishida
a6be16b556 [TBDGen] support targets instead of arch&platform 2019-10-30 11:05:51 -07:00
Harlan Haskins
e69fa3bcf5 Merge pull request #27746 from harlanhaskins/away-in-a-mangler
[TBDGen] Mangle symbols before putting them in the TBD
2019-10-17 14:23:03 -07:00
Harlan Haskins
4389c5a103 [TBDGen] Use TAPI's defaults for compatibility_version and current_version
Stop hard-coding the default to 1.0.0 for dylibs and let TAPI pick the
right one.
2019-10-17 11:17:27 -07:00
Harlan Haskins
c94b952a54 [TBDGen] Mangle symbols before putting them in the TBD
The linker expects to see mangled symbols in the TBD, otherwise it won't
be able to link anything. Use LLVM's mangler to mangle them.

Fixes rdar://54055049
2019-10-16 18:50:54 -07:00
swift-ci
2ff5de58b2 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-24 21:24:11 -07:00
Doug Gregor
9b20012ee1 Merge pull request #27322 from DougGregor/property-wrapper-composition-di
[DI] Support definite initialization for composed property wrappers.
2019-09-24 21:22:43 -07:00
Brent Royal-Gordon
051159f3b4 Merge branch 'master' into master-rebranch
# Conflicts:
#	lib/TBDGen/TBDGen.cpp
2019-09-24 19:04:43 -07:00
Brent Royal-Gordon
97febd42a9 Merge branch 'master' into master-rebranch
# Conflicts:
#	lib/TBDGen/TBDGen.cpp
2019-09-24 18:52:04 -07:00
Harlan Haskins
ccd534d139 [TBD] Ensure swift-abi-version is kept in sync with IRGen (#27347)
The TAPI_SWIFT_ABI_VERSION macro was never updated in sync with
IRGen::swiftVersion, so just expose that value through
irgen::getSwiftABIVersion() and use it in TBDGen.

Fixes rdar://55643763
2019-09-24 18:48:29 -07:00
Harlan Haskins
29bc645104 [TBDGen] Set installapi flag only when building in installapi (#27315)
Previously, we would unconditionally set the `installapi` flag, which
hard errors when trying to merge with a TAPI-generated TBD file that
was generated during the install phase.

Fixes rdar://42406088
2019-09-24 09:52:12 -07:00
Doug Gregor
a1541a19df [TBDGen] Only emit backing initializer for non-resilient properties. 2019-09-24 09:11:54 -07:00
Doug Gregor
4ba1833ca2 [TBDGen] Emit property wrapper backing initializer symbol 2019-09-24 09:11:54 -07:00
Cyndy Ishida
3c1cb4e94b TBD: clean out tapi from repo
Now that tbd writer/reader is in llvm, theres no reason to copy/paste the code in swift.
2019-09-20 14:03:01 -07:00
Slava Pestov
a0e160e215 AST: Refactor Decl::isWeakImported() API a little bit
First, remove the AvailabilityContext parameter; it was confusing because
we actually always want to use the deployment target here.

Then, split this method up into three methods:

- isAlwaysWeakImported(): simply checks for a @_weakLinked attribute, either
  on the declaration itself or one of its parent contexts.

- getAvailabilityForLinkage(): returns the OS version availability when
  this declaration was introduced, or if the declaration does not have
  explicit availability, check it's storage (if its an accessor), or its
  parent contexts.

- isWeakImported(ModuleDecl *fromModule): combines these two checks to
  determine if the declaration should be weak linked when referenced from
  the given module, or if it might be weak referenced from some module
  (if the module parameter is null).
2019-09-06 20:08:40 -04:00
Slava Pestov
6c5ecb5fc9 AST: Introduce AbstractStorageDecl::visit{Parsed,Emitted}Accessors() 2019-08-06 16:30:13 -04:00
Slava Pestov
c3fefc0280 TBD: Be sure to visit enum element default arguments
Enum element default arguments is a recent addition to the language.
With -enable-testing, default arguments can have public linkage.

Fixes <rdar://problem/53948283>.
2019-08-05 15:35:18 -04:00
Slava Pestov
0c5d52d860 AST: Introduce AbstractStorageDecl::get{Parsed,Opaque}Accessor()
Also, change visitOpaqueAccessors() to call getOpaqueAccessor() instead of
asserting if the expected accessor does not exist.
2019-08-02 19:34:43 -04:00
Slava Pestov
1ee2db4520 AST: Accessors no longer appear as members of their parent DeclContext
Accessors logically belong to their storage and can be synthesized
on the fly, so removing them from the members list eliminates one
source of mutability (but doesn't eliminate it; there are also
witnesses for derived conformances, and implicit constructors).

Since a few ASTWalker implementations break in non-trivial ways when
the traversal is changed to visit accessors as children of the storage
rather than peers, I hacked up the ASTWalker to optionally preserve
the old traversal order for now. This is ugly and needs to be cleaned up,
but I want to avoid breaking _too_ much with this commit.
2019-07-30 15:56:00 -04:00
Slava Pestov
28f1bb99b3 TBD: Use SILWitnessVisitor instead of baking in knowledge of witness table layout 2019-07-24 13:11:20 -04:00
Slava Pestov
4c499fd4ac AST: Stop passing around LazyResolvers in various places 2019-07-06 00:43:22 -04:00