Commit Graph

1534 Commits

Author SHA1 Message Date
Butta
a86b25aa84 [cxx-interop][android] Exclude Android from the list of platforms to link against the swiftstd library 2022-12-26 00:13:53 +05:30
swift-ci
f476abf4a1 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-20 17:13:36 -08:00
Pavel Yaskevich
b83b0943b5 [SILDeclRef] RuntimeMetadata: Add a special kind for runtime attribute generator
A new `RuntimeAttributeGenerator` is used to reference runtime
attribute generator functions synthesized by SILGen.
`#function` magic literal points to the declaration that declaration
attribute is attached to.
2022-12-20 09:45:01 -08:00
Pavel Yaskevich
5442d30866 [IRGen] RuntimeMetadata: Emit runtime discoverable attributes section
Each entry relates an attribute declaration to a list of all
declarations it's associated with together with a generator
function to acquire instance of the attribute value.
2022-12-20 09:45:01 -08:00
swift-ci
7cec431480 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-19 16:24:07 -08:00
Arnold Schwaighofer
5004cee9b0 Merge pull request #62686 from aschwaighofer/testing_debacle
IRGen: Don't treat internal but visible via testable import classes as having fragile layout
2022-12-19 16:08:03 -08:00
Arnold Schwaighofer
20ff4dfc57 IRGen: Don't treat internal but visible via testable import classes as having fragile layout
That does not work if there is a resilient class in the hiearchy from a
different module than the testable imported one.  Rather treat an
internal but testable imported class as having resilient metadata.

The scenario that does not work assuming we can build a fragile layout
is the following.

FrameworkA is resilient and defines a public class `Base` with a stored field.
FrameworkB is resilient and defines an internal class `Sub` that inherits from
the class `Base` in FrameworkA and adds some fields. FrameworkB is compiled
with enable-testing.
The test case testable imports FrameworkB and accesses a field in the
internal class `Base` from FrameworkB. The test case only has access to
FrameworkA's public swiftinterface file and therefore does not know
`Base`'s layout.  The layout computation for `Sub` cannot take the field
from `Base` into account and things fail silently.

rdar://103323275
2022-12-19 07:35:56 -08:00
swift-ci
e668a49808 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-17 08:34:07 -08:00
Slava Pestov
5485e54ef9 IRGen: Remove unused function 2022-12-16 16:24:48 -05:00
swift-ci
2a6e9d30eb Merge remote-tracking branch 'origin/main' into rebranch 2022-12-14 19:54:28 -08:00
swift-ci
7631ac7210 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-14 16:34:23 -08:00
Adrian Prantl
06a54432ab Sink isFixedBuffer into DebugTypeInfo and ensure the enclosed types aren't
emitted with the size of the fixed buffer.
2022-12-14 14:18:28 -08:00
Adrian Prantl
9a4cb7999e Disambiguate constructors for type metadata (NFC) 2022-12-14 11:34:51 -08:00
Ben Barham
68d5d1f9ca Merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
  lib/Frontend/CompilerInvocation.cpp - legacy pass manager removed
2022-12-07 10:13:47 -08:00
Egor Zhdan
44109594fb Merge pull request #61160 from apple/egorzhdan/cxx-static
[cxx-interop] Make `Cxx` Swift library static
2022-12-07 16:09:25 +00:00
Egor Zhdan
c2c3ea7e07 [cxx-interop] Make Cxx Swift library static
Instead of a dynamic `swiftCxx.dylib` library, let's build a static library to simplify backdeployment and reduce potential compatibility difficulties in the future.

This also adds `NO_LINK_NAME` option to `add_swift_target_library` to prevent the CMake scripts from passing `-module-link-name` to swiftc when building a given module. This fixes linker errors, which would otherwise occur due to the force-load symbol name (`_swift_FORCE_LOAD_$xyz`) being emitted for the libraries that are now static (`swiftCxx`, `swiftstd`).
2022-12-07 12:37:25 +00:00
Arnold Schwaighofer
39e5e3990d IRGen: Co-locate metadata instatiation/completions/accessor functions in a special section
For spatial locality on startup.

Hide collocating metadata functions in a separate section behind a flag.
The default is not to collocate functions.

rdar://101593202
2022-12-05 09:52:04 -08:00
swift-ci
c2dea376a3 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-02 08:53:44 -08:00
Arnold Schwaighofer
bb80f10ecc Revert "Merge pull request #62275 from aschwaighofer/rdar102481054"
This reverts commit 3617b7603c, reversing
changes made to 58a519a5c1.

This causes issues for the linker and branches accross sections if
addresses are too far apart.
2022-12-01 11:36:04 -08:00
Erik Eckstein
d89c6b2d70 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-01 07:48:51 +01:00
Dario Rexin
3cf40ea504 [IRGen] Re-introduce TypeLayout strings (#62059)
* Introduce TypeLayout Strings

Layout strings encode the structure of a type into a byte string that can be
interpreted by a runtime function to achieve a destroy or copy. Rather than
generating ir for a destroy/assignWithCopy/etc, we instead generate a layout
string which encodes enough information for a called runtime function to
perform the operation for us. Value witness functions tend to be quite large,
so this allows us to replace them with a single call instead. This gives us the
option of making a codesize/runtime cost trade off.

* Added Attribute @_GenerateLayoutBytecode

This marks a type definition that should use generic bytecode based
value witnesses rather than generating the standard suite of
value witness functions. This should reduce the codesize of the binary
for a runtime interpretation of the bytecode cost.

* Statically link in implementation

Summary:
This creates a library to store the runtime functions in to deploy to
runtimes that do not implement bytecode layouts. Right now, that is
everything. Once these are added to the runtime itself, it can be used
to deploy to old runtimes.

* Implement Destroy at Runtime Using LayoutStrings

If GenerateLayoutBytecode is enabled, Create a layout string and use it
to call swift_generic_destroy

* Add Resilient type and Archetype Support for BytecodeLayouts

Add Resilient type and Archetype Support to Bytecode Layouts

* Implement Bytecode assign/init with copy/take

Implements swift_generic_initialize and swift_generic_assign to allow copying
types using bytecode based witnesses.

* Add EnumTag Support

* Add IRGen Bytecode Layouts Test

Added a test to ensure layouts are correct and getting generated

* Implement BytecodeLayouts ObjC retain/release

* Fix for Non static alignments in aligned groups

* Disable MultiEnums

MultiEnums currently have some correctness issues with non fixed multienum
types. Disabling them for now then going to attempt a correct implementation in
a follow up patch

* Fixes after merge

* More fixes

* Possible fix for native unowned

* Use TypeInfoeBasedTypeLayoutEntry for all scalars when ForceStructTypeLayouts is disabled

* Remove @_GenerateBytecodeLayout attribute

* Fix typelayout_based_value_witness.swift

Co-authored-by: Gwen Mittertreiner <gwenm@fb.com>
Co-authored-by: Gwen Mittertreiner <gwen.mittertreiner@gmail.com>
2022-11-29 21:05:22 -08:00
swift-ci
e45db33b8d Merge remote-tracking branch 'origin/main' into rebranch 2022-11-29 14:54:58 -08:00
Arnold Schwaighofer
082349ebc7 Revert "Merge pull request #62203 from apple/revert-61984-colocate_instantiation"
This reverts commit 1f3e159cfe, reversing
changes made to 103b4a89c2.

Re-applies "IRGen: Co-locate metadata instatiation/completions/accessor
functions in a special section" for MachO only. The original change broke lldb
on aarch64 linux.

rdar://102481054
2022-11-28 06:27:12 -08:00
swift-ci
69b7f934d6 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-18 23:53:31 -08:00
Mishal Shah
a0a8881012 Revert "IRGen: Co-locate metadata instatiation/completions/accessor functions in a special section" 2022-11-18 21:04:21 -08:00
swift-ci
b96dbfdcb8 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-16 06:54:48 -08:00
Arnold Schwaighofer
440b809f93 Fix MACH-O section attribute
Credit to Lang Hames who identified the fix.
2022-11-14 06:21:37 -08:00
Arnold Schwaighofer
32cf8073af Fix COFF section name 2022-11-14 06:20:21 -08:00
Arnold Schwaighofer
6a853fa91b IRGen: Co-locate metadata instatiation/completions/accessor functions in a special section
For spatial locality on startup.

rdar://101593202
2022-11-14 06:18:00 -08:00
swift-ci
c6a647ae06 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-13 20:33:41 -08:00
Doug Gregor
5ab6b72604 [Macros] Turn Macro into a declaration node.
Although the declaration of macros doesn't appear in Swift source code
that uses macros, they still operate as declarations within the
language. Rework `Macro` as `MacroDecl`, a generic value declaration,
which appropriate models its place in the language.

The vast majority of this change is in extending all of the various
switches on declaration kinds to account for macros.
2022-11-13 12:21:29 -08:00
Arnold Schwaighofer
d45fd3c4ac IRGen: Adjust to new AddressSanitizer's way of marking globals to be ignored
rdar://102152139
2022-11-11 09:55:16 -08:00
Arnold Schwaighofer
d68dc2d06e IRGen: objc_direct method calls have a different convention
objc_direct methods no longer have the CMD argument.

rdar://102151993
2022-11-10 12:55:51 -08:00
Richard Wei
56e7cce809 [Macros] Parse MacroExpansionExpr and MacroExpansionDecl
Introduce `MacroExpansionExpr` and `MacroExpansionDecl` and plumb it through. Parse them in roughly the same way we parse `ObjectLiteralExpr`.

The syntax is gated under `-enable-experimental-feature Macros`.
2022-10-21 01:50:35 -07:00
Becca Royal-Gordon
82d78a384f Merge pull request #60630 from beccadax/at-implementation
Add @_objcImplementation
2022-10-20 17:14:21 -07:00
Egor Zhdan
6a88f75072 [cxx-interop] Implicitly import Cxx module
This lifts the requirement for the user to explicitly add `import Cxx` in Swift code that relies on protocols from the `Cxx` module, such as `CxxSequence`.
2022-10-19 15:00:50 +01:00
Becca Royal-Gordon
ba1ec90419 Generate IR for @_objcImpls
This commit begins to generate correct metadata for @_objcImplementation extensions:

• Swift-specific metadata and symbols are not generated.
• For main-class @_objcImpls, we visit the class to emit metadata, but visit the extension’s members.
• Includes both IR tests and executable tests, including coverage of same-module @objc subclasses, different-module @objc subclasses, and clang subclasses.

The test cases do not yet cover stored properties.
2022-10-18 17:21:56 -07:00
swift-ci
9811f774fd Merge pull request #61198 from beccadax/the-names-of-const
[NFC] Emit descriptive string constant names
2022-10-04 12:27:37 -07:00
Arnold Schwaighofer
3905955589 Merge pull request #61232 from aschwaighofer/wip_opaque_ptr_2
IRGen: Pass the elementType of pointers through to operations
2022-10-04 10:56:41 -07:00
Arnold Schwaighofer
5a46517f44 Fix a few places that are missing IGM.DebugInfo->emitArtificialFunction 2022-10-04 06:23:25 -07:00
Arnold Schwaighofer
d810b0f7e4 IRGen: Pass the elementType of pointers through to operations
In preparation for moving to llvm's opaque pointer representation
replace getPointerElementType and CreateCall/CreateLoad/Store uses that
dependent on the address operand's pointer element type.

This means an `Address` carries the element type and we use
`FunctionPointer` in more places or read the function type off the
`llvm::Function`.
2022-10-03 15:27:12 -07:00
Nate Chandler
71d993886a [IRGen] Emit bit for @main into entry section.
The _swift5_entry section contains a relative pointer to the entry-point
function (spelled variously _main and @main depending on context).
Support differentiating whether that entry point originates from a type
annotated @main or something else (i.e. main.swift) via a second
relative-pointer-sized field.  For now, that field is just a bit: 1 if
there is a type annotated @main, 0 otherwise.  In the future, that field
could be a relative pointer to the type descriptor for the type.
2022-09-26 11:02:09 -07:00
Becca Royal-Gordon
04f82b424c [NFC] Emit descriptive string constant names
Modify IRGen to emit “anonymous” string constants with names of the form `@.str.<len>.<contents>` (with a special mangling for internal `\0` characters). This makes it much easier to write IRGen tests that check for the contents of strings, because matching the constant name also implies that the constant has the expected content.
2022-09-21 11:40:15 -07:00
Hamish Knight
01c7c16c18 [IRGen] Allow lazy emission of coverage mapped functions
We previously eagerly emitted such functions to
ensure that their name data is emitted through the
profiler increment. Now that are able to emit the
profile name data separately, this is unnecessary,
and we can avoid emitting their definitions.
2022-09-16 15:47:17 +01:00
Slava Pestov
c1b8690401 AST: Introduce special Builtin.TheTupleType singleton 2022-09-10 00:26:42 -04:00
Erik Eckstein
b2b44c0d83 Swift Optimizer: add the StackProtection optimization
It decides which functions need stack protection.

It sets the `needStackProtection` flags on all function which contain stack-allocated values for which an buffer overflow could occur.

Within safe swift code there shouldn't be any buffer overflows.
But if the address of a stack variable is converted to an unsafe pointer, it's not in the control of the compiler anymore.
This means, if there is any `address_to_pointer` instruction for an `alloc_stack`, such a function is marked for stack protection.
Another case is `index_addr` for non-tail allocated memory.
This pattern appears if pointer arithmetic is done with unsafe pointers in swift code.

If the origin of an unsafe pointer can only be tracked to a function argument, the pass tries to find the root stack allocation for such an argument by doing an inter-procedural analysis.
If this is not possible, the fallback is to move the argument into a temporary `alloc_stack` and do the unsafe pointer operations on the temporary.

rdar://93677524
2022-09-08 08:42:25 +02:00
Erik Eckstein
3e1ff0a5b7 IRGen: move the EnableStackProtector option from IRGenOptions to SILOptions.
... because we need it in the SIL pass pipeline, too.
Also, add Swift bridging for that option.
2022-09-08 08:42:24 +02:00
John McCall
847c060eaf Fix a potential use-after-free in lazy global emission.
Extended existential type shapes can trigger this by introducing
more entities (and thus causing GlobalVars to be rehashed) during
the lazy-emission callback.

Fixes rdar://98995607
2022-08-25 16:31:17 -04:00
Allan Shortlidge
8ec4264d9b IRGen: Fix IR linkage computation for inlined function references from clang modules imported @_weakLinked.
Part of rdar://98521248
2022-08-19 10:33:04 -07:00
Allan Shortlidge
40eb1422bb IRGen/SIL: Fix IR linkage computation for inlined function references from modules imported @_weakLinked.
Include the parent `ModuleDecl` when serializing a `SILFunction` so that it is available on deserialized functions even though the full `DeclContext` is not present. With the parent module always available we can reliably compute whether the `SILFunction` comes from a module that was imported `@_weakLinked`.

Serialize the `DeclContext` member of `SILFunction` so that it can be used to look up the module that a function belongs to in order to compute weak import status.

Resolves rdar://98521248
2022-08-19 09:56:45 -07:00