Commit Graph

1537 Commits

Author SHA1 Message Date
Doug Gregor
7e6f52308d [Runtime] Move conformance kind into low bits of witness table reference.
Move the 2-bit conformance reference kind from the conformance flags (which
is meant to go away) into the lower two bits of the witness table offset.
2018-01-02 12:34:06 -08:00
Doug Gregor
8c668ba524 [Runtime] Rename the segment for protocol conformance records.
The format of protocol conformance records will be changing in Swift 5, so
rename the segment (from, e.g., __swift2_proto to __swift5_proto) to allow
Swift < 5 and Swift 5+ runtimes to coexist.
2018-01-02 11:01:51 -08:00
David Ungar
51d3165874 NFC: Clarifying uses of NumThreads.
Add hasMultipleGMs predicate to SILOptions.
Rename parameters to TBD file handling to better reflect abstraction boundary.

fix
2017-12-16 13:58:01 -08:00
swift-ci
a93717988c Merge pull request #13211 from compnerd/COFF-registration 2017-12-09 14:41:41 -08:00
Saleem Abdulrasool
899103cfa8 COFF: restructure metadata registration
Restructure the COFF metadata handling to use the linker section
grouping to emit section start/stop markers in the appropriate location.
This allows us to lookup the sections statically without having to the
walk the entire image structure.

Introduce a constructor for PE/COFF binaries.  This will ensure that the
registration occurs for all modules appropriately.  This should resolve
rdar://problem/19045112.  The registration should occur prior to
`DllMain` being invoked from `DllMainCRTStartup`.
2017-12-08 16:15:07 -08:00
Slava Pestov
e04f6e85bd IRGen: Add mangling for class metadata base offset
Also remove some misleading comments from GenDecl.cpp, where
we were giving examples of the old mangling.
2017-12-08 13:50:56 -08:00
Doug Gregor
4f8edeb913 [Runtime] Always fail to find a conditional conformance at runtime.
Proper evaluation of conditional conformances at runtime (e.g., as part of
dynamic casting) is too large to tackle in the Swift 4.1 timeframe. For now,
record that a conformance is conditional in the protocol conformance record,
and always return "does not conform" to such types.

Fixes rdar://problem/35761301.
2017-12-04 16:51:52 -08:00
Saleem Abdulrasool
d8552ceb9e IRGen: ensure that ObjC sections match on all targets
Adjust the IRGen for ObjC interop to ensure that the section that
metadata is emitted into the correct section for non-MachO targets.

This also adds a more comprehensive test for ensuring that the IRGen can
now be tested on all targets.  Since the ObjC interop is now
controllable via the driver, this test does not require that the
objc_interop feature is present as it is a IRGen test.

This is the first step to remove the `REQUIRES: objc_interop` from the
IRGen tests.
2017-12-03 15:55:44 -08:00
Saleem Abdulrasool
0c42b57962 ELF: restructure image metadata registration
Restructure the ELF handling to be completely agnostic to the OS.
Rather than usng the loader to query the section information, use the
linker to construct linker tables and synthetic markers for the
beginning and of the table.  Save off the values of these pointers and
pass them along through the constructor to the runtime for registration.

This removes the need for the begin/end objects.  Remove the special
construction of the begin/end objects through the special assembly
constructs, preferring to do this in C with a bit of inline assembly to
ensure that the section is always allocated.

Remove the special handling for the various targets, the empty object
file can be linked on all the targets.

The new object file has no requirements on the ordering.  It needs to
simply be injected into the link.

Name the replacement file `swiftrt.o` mirroring `crt.o` from libc.  Merge
the constructor and the definition into a single object file.

This approach is generally more portable, overall simpler to implement,
and more robust.

Thanks to Orlando Bassotto for help analyzing some of the odd behaviours
when switching over.
2017-11-28 10:04:04 -08:00
Joe Shajrawi
d8289aa3ec Code size: destroy_addr outline 2017-11-17 16:10:27 -08:00
Joe Shajrawi
f6781deaf8 copy_addr outline: cleanups based on review 2017-11-16 23:19:33 -08:00
Joe Shajrawi
62d823c56d Code size: Do not use a global state for isOutlined 2017-11-15 15:28:27 -08:00
Joe Shajrawi
5aff0891b7 Code size: copy_addr outline part 2 - Support Archetypes 2017-11-15 15:26:44 -08:00
Erik Eckstein
8846fdf814 IRGen: consider the function-level optimization mode for setting the minsize attribute on llvm functions. 2017-11-14 11:25:02 -08:00
Erik Eckstein
90c21be191 Unify the implementation of optimization mode in various option classes.
This commit is mostly refactoring.

*) Introduce a new OptimizationMode enum and use that in SILOptions and IRGenOptions
*) Allow the optimization mode also be specified for specific SILFunctions. This is not used in this commit yet and thus still a NFC.

Also, fixes a minor bug: we didn’t run mandatory IRGen passes for functions with @_semantics("optimize.sil.never")
2017-11-14 11:25:02 -08:00
Arnold Schwaighofer
f10f8d55dc IRGen: Nuke isSILOnly usage
It queried for [transparent] [serialized] definitions and only had an effect
when the module was compiled with -Onone because we remove [serialized]
as part of the optimizer pipeline.

It was causing bad effects when the module we imported from was compiled
with -Onone:

 The definition would be marked internal in said module.

and the importing module is compile with -O:

 The definition would be marked as available_externally.

because neither would guaranteed the presence of a definition of the
imported symbol available to the importer.

rdar://35100697
2017-11-13 14:33:39 -08:00
Huon Wilson
6dd8bec47e [AST] Unify computation of 'has arguments?' for witness table accessors. 2017-11-09 17:51:48 -08:00
Huon Wilson
b9336c7389 [IRGen] Dynamically fill in conditional conformance wtables.
This requires the witness table accessor function to gain two new parameters: a
pointer to an array of witness tables and their count. These are then passed down
to the instantiation function which reads them out of the array and writes them
into the newly-allocated witness table.

We use the count to assert that the number of conditional witness tables passed
in is what the protocol conformance expects, which is especially useful while
the feature is still experimental: it is a compiler/runtime bug if an incorrect
number is passed.
2017-11-08 17:02:50 -08:00
Greg Parker
9a38e609af [IRGen][runtime] Reduce object header to 8 bytes on 32-bit platforms. (#12790)
SR-4353, rdar://29765800
2017-11-08 02:50:11 -08:00
Slava Pestov
6fbf8b81a3 SIL: Kill completely bogus getTypeLinkage() function
- The overload of operator^ on FormalLinkage, while cute, was only used
  in this one place, and does not behave like an XOR.

- The structural type walk was totally unnecessary in the first place,
  because we were only ever calling getTypeLinkage() with builtin types
  and nominal types.

- Furthermore, the structural type walk was doing the wrong thing with
  nested nominal types, because the linkage of a nested type A.B
  should not be the intersection of the linkage of A and A.B. If A is an
  imported type and A.B is defined in an extension of A, we would give
  the metadata of A.B shared linkage, which is wrong.
2017-11-03 16:03:00 -07:00
Davide Italiano
340c500dcc [IRGen] Cleanup unused lambda capute recently introduced. NFCI. 2017-11-02 17:56:57 -07:00
Joe Shajrawi
8c67caa5c6 Merge pull request #12687 from shajrawi/outline_copyddr
Code Size: Outline copy addr instruction
2017-11-01 10:47:11 -07:00
Greg Parker
d6e1866344 [SIL] Make @_silgen_name and @_cdecl functions immune to some optimizations (#12696)
@_silgen_name and @_cdecl functions are assumed to be referenced from
C code. Public and internal functions marked as such must not be deleted
by the optimizer, and their C symbols must be public or hidden respectively.

rdar://33924873, SR-6209
2017-11-01 01:41:05 -07:00
Joe Shajrawi
f4db36426c Code Size: Outline copy addr instruction 2017-10-31 17:03:48 -07:00
Doug Gregor
cd3c63cbfd [AST] Stop including GenericSignature.h in other headers.
Except GenericEnvironment.h, because you can't meaningfully use a
GenericEnvironment without its signature. Lots less depends on
GenericSignature.h now. NFC
2017-10-12 14:23:46 -07:00
Roman Levenstein
9e07d5e0b0 Remove LinkEntity::isFragile which is always false now.
And remove all the code that is dead because of it.
2017-10-05 15:51:17 -07:00
Roman Levenstein
b13c776d10 Fix a couples of bugs related to witness method serialization 2017-10-05 15:51:11 -07:00
Roman Levenstein
692575ffb1 Remove ResilientStrategy::Fragile 2017-10-04 14:50:16 -07:00
Arnold Schwaighofer
3d34fb3b07 IRGen: Fix linkage for shared declarations
They need external linkage not linkonce_odr which can only be used by defintions
not declarations.
This got exposed by clang imported protocol witness table declarations.
They get assigned shared linkage since they are potentially not unique.

rdar://26563441
2017-09-26 13:26:07 -07:00
Slava Pestov
8b73de60a9 IRGen: Remove GenericTypeRequirements::ParentType
Finally, remove the parent type metadata argument from type
constructors.

Now that type constructors don't take a parent metadata pointer,
we can hit some asserts concerning type constructors that do not
have any parameters. This happens when you define a concrete type
in a fully-constrained extension of a generic type.

A more efficient ABI would use concrete type metadata for these
cases, but that would be a bigger change that we can do later, so
for now just relax these assertions.

This resolves a runtime crasher since a circular metadata case is
no longer circular. I renamed the crasher to reference the more
specific radar since the more general issue of circular metadata
is still unresolved.
2017-09-25 15:45:17 -07:00
Joe Groff
d7008d30c9 IRGen: Refactor so that TypeInfos can provide type verifier logic.
NFC yet, but this will allow things like *StructTypeInfo emitting code to check fixed struct field offsets against the runtime.
2017-09-21 15:31:12 -07:00
Slava Pestov
0dcfd320ae IRGen: Remove usages of getDeclaredTypeOfContext() 2017-09-19 22:12:29 -07:00
Erik Eckstein
5d56a73664 IRGen: fix generation of statically initialized objects with a larger alignment than the default.
fixes rdar://problem/34263821
2017-09-05 15:39:16 -07:00
Jordan Rose
449cd98997 Excise "Accessibility" from the compiler (3/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

Rename AccessibilityAttr to AccessControlAttr and
SetterAccessibilityAttr to SetterAccessAttr, then track down the last
few uses of "accessibility" that don't have to do with
NSAccessibility. (I left the SourceKit XPC API alone because that's
supposed to be more stable.)
2017-08-28 13:27:59 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00
John McCall
9a228e96e1 Change the structure of emitted protocol and generic-wtable metadata:
- Always include an array of requirement descriptors in the protocol
  descriptor.  For now, this doesn't contain anything except a general
  requirement kind and an optional default implementation, but eventually
  this can be augmented with type / name metadata.  This array is always
  emitted as constant.

- Guarantee the value of the extent fields in a protocol descriptor and
  slightly tweak their meaning.

- Move the private-data field out of line in a generic witness table
  descriptor so that the main descriptor can be emitted as constant.

- Rely on IRGen's notion of the witness-table layout instead of assuming
  that SILWitnessTable and SILDefaultWitnessTable match the actual
  physical layout.

This version of the patch uses a hack in which we assign internal rather
than private linkage to certain symbols in order to work around a Darwin
linker bug.
2017-08-25 01:42:44 -04:00
Erik Eckstein
9c6fe76927 SIL, IRGen: add instructions "object" and "global_value” to support statically initialized objects.
This commit contains:
-) adding the new instructions + infrastructure, like parsing, printing, etc.
-) support in IRGen to generate global object-variables (i.e. "heap" objects) which are statically initialized in the data section.
-) IRGen for global_value which lazily initializes the object header and returns a reference to the object.

For details see the documentation of the new instructions in SIL.rst.
2017-08-23 09:15:49 -07:00
John McCall
bd8246351e Add an AST-level abstraction for representing an abstract associated
type or conformance requirement.  NFC.
2017-08-10 20:15:20 -04:00
Arnold Schwaighofer
f4a810f7e4 IRGen: AttributeList related fixes for master next 2017-07-31 11:17:51 -07:00
John McCall
d4d2145ad8 Merge branch 'master' into master-next 2017-07-29 15:48:00 -04:00
John McCall
a0f20f673d Switch all of the indirect-call code in IRGen to FunctionPointer.
To make this stick, I've disallowed direct use of that overload of
CreateCall.  I've left the Constant overloads available, but eventually
we might want to consider fixing those, too, just to get all of this
code out of the business of manually remembering to pass around
attributes and calling conventions.

The test changes reflect the fact that we weren't really setting
attributes consistently at all, in this case on value witnesses.
2017-07-28 23:26:35 -04:00
Bob Wilson
5f02db4d3e Merge remote-tracking branch 'origin/master' into master-next 2017-07-20 21:59:23 -07:00
John McCall
750d397909 Substantially rework how IRGen handles function pointers.
The goals here are four-fold:
  - provide cleaner internal abstractions
  - avoid IR bloat from extra bitcasts
  - avoid recomputing function-type lowering information
  - allow more information to be propagated from the function
    access site (e.g. class_method) to the call site

Use this framework immediately for class and protocol methods.
2017-07-20 14:33:18 -04:00
swift-ci
e98182387b Merge remote-tracking branch 'origin/master' into master-next 2017-07-11 12:23:35 -07:00
Joe Groff
101788dbd4 IRGen: Support for computed properties with dependent generic context.
Use the KeyPath implementation's new support for instantiating and dealing with captures to lower the generic context required to dispatch computed accessors with dependent generics.
2017-07-06 20:07:41 -07:00
swift-ci
b28a1093da Merge remote-tracking branch 'origin/master' into master-next 2017-06-29 15:09:18 -07:00
Doug Gregor
623d72db3c [AST] Make the "requirement signature" of a protocol a flat array.
Rather than pretend that the requirement signature of a protocol is a
full, well-formed generic signature that one can meaningfully query,
treat it as a flat set of requirements. Nearly all clients already did
this, but make it official. NFC
2017-06-29 14:01:49 -07:00
Greg Parker
7b009eccde Merge remote-tracking branch 'origin/master' into master-next 2017-06-28 15:25:17 -07:00
Arnold Schwaighofer
c9ef5532ff IRGen: Add the created LLVM function to the current module before the call to the
IRGenFunction() constructor

A change in LLVM will require the function to have a module parent when we
insert the epilogue alloca in the IRGenFunction constructor.

rdar://32998781
2017-06-28 12:03:56 -07:00
swift-ci
28e3315046 Merge remote-tracking branch 'origin/master' into master-next 2017-06-08 23:08:34 -07:00