Commit graph

242 commits

Author SHA1 Message Date
Martin Kinkelin
5f46c65ab5
Fix v1.31 regression wrt. unresolved IrAggr (#4312)
And use `IrTypeClass::getVtblType()` to get the vtable LLVM array
type, instead of deriving it from the `IrClass::getVtblSymbol()`
global (invoking that function may define the vtable!).

I've hit some compiler crashes for the Symmetry code base, on
Windows only. I guess the problem surfaced due to
`-link-defaultlib-shared`, which on Windows causes some vtables of
instantiated classes to be defined whenever accessing the vtable
symbol. I don't have a reduced test case unfortunately.
2023-02-06 17:02:07 +01:00
Martin Kinkelin
b7624aa625 Upgrade frontend & libs to pre-DMD-monorepo state (dlang/dmd@20bd0cacbd) 2022-09-12 16:14:16 +02:00
Nicholas Wilson
1ba58141ae
Remove use of getPointerElementType from GC2Stack (#4113)
Augment the type info for arrays to include the element type in addition to the array type as a second type-as-metadata MDNode.

Use this in place of looking up the element type from the array type
2022-09-06 02:33:39 +00:00
Nicholas Wilson
b41ca60e67
Avoid use of getPointerElementType in typeinf.cpp (#4022) 2022-09-01 19:17:57 +08:00
Martin Kinkelin
5a2f3ed87f Upgrade frontend & libs to v2.099.0-beta.1+ (dlang/dmd@1c31d85613) 2022-02-16 20:52:07 +01:00
Martin Kinkelin
86f430c039 Slightly revise frontend diff
E.g., preferring local imports for less merge conflict potential.
2021-09-11 17:34:51 +02:00
Martin Kinkelin
369cfd13ce Adapt to TY enum class 2021-09-07 16:51:19 +02:00
Martin Kinkelin
9865e459d1 Windows: Make implicit dllimport more selective
* Newly require `-link-defaultlib-shared` for implicit dllimport.
  E.g., this enables to compile druntime DLL with `-fvisibility=public`
  for pure exports and no (local) imports (such as builtin TypeInfos).
* `-link-defaultlib-shared` alone now only implicitly imports symbols
  from druntime/Phobos.
  This simplifies building complex DLLs linked against a bunch of
  static libs (dub only supports static lib dependencies!); the static
  libs don't need to be compiled with `-fvisibility=public` anymore
  (if the DLL itself isn't either), `-link-defaultlib-shared` is
  sufficient.
  This is mainly useful for existing DLLs with explicit exports, to make
  them link against *shared* druntime/Phobos and so end up with a single
  druntime/Phobos for the whole process.
2021-06-14 17:47:32 +02:00
Martin Kinkelin
ee0d5fbe3c Windows: Default to dllexport with -shared, and enforce dllimport with -link-defaultlib-shared 2021-05-03 20:54:57 +02:00
Martin Kinkelin
49caa9e8a0 Windows: Dllimport aggregate globals too
Init symbols, TypeInfos (classes only) & vtables - unless defined in a
root module. For explicitly exported aggregates, or, with
`-fvisibility=public`, all aggregates.
2021-04-29 17:22:12 +02:00
Martin Kinkelin
0d7d776032 Fix TypeInfo_Interface.info regression
This fixes a new object.d unittest showing this pretty severe bug, which
appears to be a v1.25 regression. The `TypeInfo_Interface.info` field (a
TypeInfo_Class ref) pointed to its own TypeInfo_Interface (not derived
from TypeInfo_Class; simply bitcast) instead of the interface's
__InterfaceZ symbol.
2021-03-07 03:59:51 +01:00
Martin Kinkelin
fe5a1776ac Merge remote-tracking branch 'origin/master' into merge-2.095 2021-01-06 23:58:20 +01:00
Martin Kinkelin
d3574b9835 DtoTypeInfoOf(): Make Loc param mandatory and move to 1st position 2020-12-13 15:15:37 +01:00
Martin Kinkelin
079858f3b2 Upgrade frontend & libs to early v2.095.0 (dlang/dmd@a4274b3c39) 2020-11-27 17:45:13 +01:00
Martin Kinkelin
145ce40b11 Extend -linkonce-templates by matching template emission scheme
I.e., *define* templated symbols in each referencing compilation unit
when using discardable linkonce_odr linkage, analogous to C++.

This makes each compilation unit self-sufficient wrt. templated symbols,
which also means increased opportunity for inlining and less need for
LTO. There should be no more undefined symbol issues caused by buggy
template culling.

The biggest advantage is that the optimizer can discard unused
linkonce_odr symbols early instead of optimizing and forwarding to the
assembler. So this is especially useful with -O to decrease compilation
times and can at least in some scenarios greatly outweigh the
(potentially very much) higher number of symbols defined by the glue
layer.

Libraries compiled with -linkonce-templates can generally not be linked
against dependent code compiled without -linkonce-templates; the other
way around works.
2020-11-13 02:41:11 +01:00
Martin Kinkelin
30921a989d Simplify TypeInfo metadata
Don't store and check a back reference to the TypeInfo global.
The association is already unambiguously expressed by the metadata name
ending with the mangled name of the TypeInfo global.

Removing this check fixes a problem when replacing a TypeInfo global at
some point via IRState::setGlobalVarInitializer() (e.g., for the
rt.util.typeinfo unittests), because llvm::ValueAsMetadata doesn't fully
support LLVM's replace-all-uses-with.
2020-10-25 17:06:16 +01:00
Martin Kinkelin
da7f8787c3 Handle IR collisions wrt. built-in TypeInfos and make them mutable
Compiling the rt.util.typeinfo unittests leads to base-typed forward
declarations of built-in TypeInfos colliding with the init symbols for
their TypeInfo_* classes in rt.util.typeinfo.

We've already had a workaround for this in one place (typinf.cpp);
extend it to the other side as well (iraggr.cpp).

Also make sure to emit the TypeInfo metadata even if the IR symbol
already exists as init symbol.

And finally, keep init symbols of built-in TypeInfo classes mutable just
like any other TypeInfo, so that e.g. synchronized() can be used on the
implicit monitor.
2020-10-25 17:06:16 +01:00
Martin Kinkelin
e9021fd6c8 Refactoring: Improve Ir{Aggr,Class,Struct} encapsulation 2020-10-24 20:07:29 +02:00
Martin Kinkelin
a6ed0e500f Emit struct TypeInfos in referencing CUs only
I.e., not in their owning CU if unused therein, but in all referencing
CUs instead, as linkonce_odr. The special member functions are still
only and unconditionally emitted in the owning CU.
2020-10-11 14:34:49 +02:00
Martin Kinkelin
64aa4fe1e3 Emit struct TypeInfos & special member functions in owning module only
Analogous to ClassInfos, incl. normal linkage (external for non-
templates, weak_odr for templates).

This enables to get rid of frontend logic wrt. whether to add
TypeInfoStructDeclarations to a module's members tree - previously,
it was defined as linkonce_odr in the owning module and each referencing
module (unless speculative) - and related extra semantic and codegen for
the special member functions.
I've gone a bit further and moved the entire TypeInfo emission for LDC
to the codegen layer; no TypeInfoDeclarations are added to the module
members anymore. Whenever we need a TypeInfo symbol during codegen, it
is declared or defined, and we don't need to rely on brittle frontend
logic with speculative-ness complications.

This might slightly increase compilation speed due to less emitted
TypeInfos and functions (possibly less work for the linker too).

A slight drawback is that the job of stripping unused struct TypeInfos
is fully delegated to the linker, as the TypeInfo is guaranteed to end
up in the owning object file due to no linkonce_odr.

Another theoretical drawback is that the optimizer can definitely not
inline xtoHash/xopEquals/xopCmp/xtoString/xdtor[ti]/xpostblit function
pointer indirections in non-owning CUs without LTO (neither the pointers
nor the special member functions are defined anymore).
These (public) members are probably hardly used directly though, and
instead used by the virtual TypeInfo_Struct methods equals/compare/
getHash/destroy/postblit, which are exclusively defined in druntime's
object.o (incl. the TypeInfo_Struct vtable) and aren't cross-module-
inlined anyway (without LTO).

Re-emitting the struct TypeInfos (and optionally the special member
functions too) into each referencing CU could be handled in our codegen
layer, which should be much simpler and more robust than the upstream
scheme.
2020-10-11 12:58:48 +02:00
Martin Kinkelin
e6a2dd852d
Fix issue #3501: Don't re-define struct TypeInfos (#3502)
Surfacing now as #3486 added a corresponding assertion.

I've tested this with an older vibe-d v0.8.6 lying around on my box.
The assertion was hit for the TypeInfo of a nested struct:

3c7ae13989/http/vibe/http/router.d (L570-L574)

I wasn't able to quickly reduce it to a stand-alone testcase and am
reluctant to put any more effort into this.
2020-07-10 23:31:15 +02:00
Martin Kinkelin
c09f7ed617 Revise struct/class/interface TypeInfo generation, incl. getting rid of GENERATE_OFFTI
I've also compared against the current DMD implementations, to make sure
we are in sync.

DMD doesn't populate `TypeInfo_Class.m_offTi` either. This seems like a
leftover of some unimplemented idea (the LDC commit introducing the
CMake option is from 2008); the normal `TypeInfo_Class.interfaces` array
contains the offsets nowadays.
2020-07-04 16:42:52 +02:00
Martin Kinkelin
40dedab1e8 Move TypeInfo_Struct emission to new ir/irstruct.cpp
Incl. getting rid of the dependence on an associated
TypeInfoStructDeclaration, which was only really needed for the mangled
name of the global.

Also slightly revise metadata generation.
2020-07-03 21:52:55 +02:00
Martin Kinkelin
ab619744f2 Refactoring: Specialize IrAggr into IrStruct and IrClass
And move ClassInfo generation from gen/classes.cpp to ir/irclass.cpp.
2020-07-01 21:28:45 +02:00
Martin Kinkelin
967947eb84 Emulate @weak functions on Windows and don't emit COMDATs for ELF anymore
Emulation for @weak global variables is still left out but should be
analogous.

The test adaptations are mostly a revert of 3893840f. The testcase has
shown that @weak hasn't worked properly for ELF (linker apparently
prefers the version in the 1st object file, independent of whether it's
weak or not), because the functions are emitted in COMDATs.
clang emits COMDATs for templates and inline functions only, not for
regular functions.
2020-05-16 20:42:57 +02:00
Martin Kinkelin
67d619e13d Merge upstream stable (dlang/dmd@e37e1be58c) 2020-05-01 23:38:55 +02:00
Martin Kinkelin
70aa3aff7c Upgrade frontend & libs to early v2.092.0 (dlang/dmd@abf2b56326) 2020-04-28 01:37:49 +02:00
Martin Kinkelin
4ac7f0554b Adapt to frontend refactorings 2019-12-22 16:29:45 +01:00
Ivan Butygin
a40c6c7fd2
Make LDC custom passes available to jit, add API for jit compiler options (#2758) 2019-09-08 09:16:05 +03:00
Martin Kinkelin
c1725809c2
-fvisibility=hidden: Hide init symbols, TypeInfos and vtables too if the associated aggregate isn't exported (#3129) 2019-08-20 01:41:26 +02:00
Martin Kinkelin
e52199469f Upgrade front-end & libs to v2.087.0-beta.1 2019-06-21 15:39:45 +02:00
Martin Kinkelin
c17cee71f3 Extend pragma(LDC_no_typeinfo) to classes and interfaces 2019-05-04 20:56:03 +02:00
Martin Kinkelin
314a64c351 Fix pragma(LDC_no_typeinfo) - elide TypeInfo emission for structs 2019-05-04 18:41:51 +02:00
Martin Kinkelin
4a23399236 Aim for consistent #includes (order + dir prefix)
I surely missed a few.
2018-10-20 16:19:46 +02:00
Martin Kinkelin
7776c4081b Upgrade frontend & libs to v2.083.0-beta.1 2018-10-20 16:19:46 +02:00
Martin Kinkelin
7dbd07dd1e Use new extern(D) dtor shims for struct/class TypeInfos
The TypeInfo may need an extern(D) wrapper accounting for ABI
differences wrt. extern(C++) dtor implementations.

This fixes `runnable/cppa.d` for 32-bit x86 targets.
2018-06-23 19:31:43 +02:00
Martin
2dea0e96ee Account for special case of builtin TypeInfos (rt.typeinfo.*)
And aid in debugging by outputting the IR type names if there are type
mismatches when declaring global variables.
2018-04-10 22:13:00 +02:00
Martin
f38a7972a5 Split up getOrCreateGlobal() in {declare,define}Global()
Making it obvious which of the two operations is performed, reducing
call args and making sure a global isn't defined multiple times via
`defineGlobal()`.

The only [intended] functional change is in gen/trycatchfinally.cpp,
where I inserted a check for an existing __cpp_type_info_ptr global when
emitting a catch for C++ exceptions.
2018-04-10 22:13:00 +02:00
Martin
e337cec78a Slightly refactor RTTIBuilder 2018-04-04 19:59:10 +02:00
Martin
24c2d3e867 Skip TypeInfo emission if there's no TypeInfo declaration
This is compatible with DMD.
2018-04-04 19:59:10 +02:00
Martin
bd623f028a Redirect access to remaining TypeInfo subtypes through gen/runtime 2018-04-04 19:59:10 +02:00
Martin
d8f60d2f5c Redirect access to object.d type declarations through gen/runtime
Not all type declarations yet (e.g., some TypeInfo subtypes are still
accessed directly), but those already wrapped as LazyType in the
gen/runtime.cpp module (with check and proper error msg in case object.d
doesn't contain a required declaration).
2018-04-04 19:59:10 +02:00
Martin
df4f854dd5 Upgrade to D v2.079.0-beta.1 2018-02-20 02:04:41 +01:00
Martin
cfad799f48 Merge 2.078.0 front-end and stdlibs 2018-01-06 01:39:18 +01:00
Martin
ad89009d6e Merge 2.077.0 front-end and stdlibs 2017-11-05 18:41:55 +01:00
Martin
3f38f9715a Get rid of special 'typeid(...)' LL types for TypeInfos
Use the real LL type representing the TypeInfo (sub)class directly and
from the beginning, i.e., already for the declaration, instead of
building an extra LL struct type (firstly opaque, then finalized when
defining the TypeInfo via RTTIBuilder).

To get this to work in all cases, the dummy TypeInfo for opaque structs
is now a complete TypeInfo_Struct, with all 11/13 fields zero-
initialized. Previously, it was a special TypeInfo (no extra
TypeInfo_Struct fields) with TypeInfo_Struct vtable, something which DMD
also emits.

Also refactor the RTTIBuilder finalize() interface - e.g., don't set the
linkage there (had to be reverted for ModuleInfos) and only take the
global variable to be defined. Cast the field initializers if required,
e.g., null pointers to appropriately typed function pointers for
TypeInfo_Struct etc.
2017-10-25 00:38:05 +02:00
Martin
3d0a127d96 Skip TypeInfo definitions for -betterC 2017-10-25 00:38:05 +02:00
kinke
d1b30d627c Backport fix for issue #2357 (#2366)
Improve robustness for TypeInfos of speculative types by only eliding
their TypeInfo definition, not the declaration of the LL global
altogether.

`DtoTypeInfoOf()` expects the LL global to be created and otherwise
fails with an assertion or segfault (e.g., issue #2357). So now only
linker errors should result in case the TypeInfo definition is missing.

Also normalize the calls to `DtoTypeInfoOf()` and revise the following
pointer bitcasts, as the LL type of forward-declared TypeInfo globals
may be opaque.
2017-10-18 20:47:09 +02:00
Martin
c251170912 Rename DtoMangled... to getIRMangled... 2017-10-07 14:06:17 +02:00
Martin
c9a3be1295 Let TargetABI fix up LLVM mangles for more special symbols
For ModuleInfos, ModuleRefs, InterfaceInfos, interface vtables & thunks.
2017-10-07 14:06:17 +02:00