Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
a236bc7
Don't generate code for compiletime only functions
UplinkCoder Apr 5, 2020
b8b66a8
Introduce the alias type
UplinkCoder Apr 5, 2020
079199b
Add serial to rootobject
UplinkCoder Apr 30, 2020
712e951
Add placeholder mangle for alias so we don't fail the unittest
UplinkCoder May 12, 2020
cea9dcd
Add test for alias function parameters
UplinkCoder May 15, 2020
09c5816
Fix test failure
UplinkCoder May 15, 2020
d218507
Add parsing for alias variables
UplinkCoder May 15, 2020
35c3720
Bypass semantic for some expressions involving Talias
UplinkCoder May 15, 2020
813adf3
Only ignore types in arguments for type functions
UplinkCoder May 16, 2020
74aebe7
Add useless stubs to astbase to make semaphore happy
UplinkCoder May 16, 2020
357af12
Allow alias parameters to match anything
UplinkCoder May 18, 2020
34e10f6
Get .stringof to work
UplinkCoder May 18, 2020
7ae58a9
Add sizeof
UplinkCoder May 19, 2020
3758e9b
Add sizeof
UplinkCoder May 19, 2020
4a0b4a8
Allow copying of TypeExp
UplinkCoder May 19, 2020
cf8aed9
Give Alias a size such that they can be used inside structs
UplinkCoder May 19, 2020
5f143f8
Consider struct with aliasType member alias types as well
UplinkCoder May 19, 2020
96b3d13
make sure we don't emit type functions
UplinkCoder May 19, 2020
6384586
Handle __traits(getAttributes) for type functions
UplinkCoder May 19, 2020
f097380
Don't codegen structs which are tainted by alias-types
UplinkCoder May 19, 2020
98d1568
Add debug printout to DotIdExp
UplinkCoder May 19, 2020
27210d8
Don't touch alias types when repainting
UplinkCoder May 19, 2020
c88bd97
Skip alias declarations
UplinkCoder May 19, 2020
d61eec3
less null derefing
UplinkCoder May 19, 2020
3e2decc
Temporary work around for against infinite recursion in scanning types
UplinkCoder May 19, 2020
ee449b4
don't count alias parameters
UplinkCoder May 19, 2020
840cf93
Don't use asttypename.d to make windows build happy
UplinkCoder May 19, 2020
12421b5
Introduce -sktf switch
UplinkCoder May 19, 2020
840646d
Don't repaint type exps
UplinkCoder May 20, 2020
82319f1
consider types which have the same pointer as equivalent
UplinkCoder May 20, 2020
fc094df
Handle appending a type exp to a mutable alias[]
UplinkCoder May 20, 2020
abbc8bb
some nice resolve helper
UplinkCoder May 21, 2020
b8405a2
Introduce TypeExpression
UplinkCoder May 25, 2020
adf468b
Add placeholder mangling char for TypeExpression
UplinkCoder May 25, 2020
4b4af4b
Add support for TypeExpression to hdrgen
UplinkCoder May 25, 2020
98bfcb1
Add IsExp handling
UplinkCoder May 25, 2020
b3714d1
Consider all alias variables to be ctfe
UplinkCoder May 25, 2020
69d84fe
Allow alias variables to be types
UplinkCoder May 25, 2020
a821910
Add test for simple type function cases
UplinkCoder May 25, 2020
4f685e7
Give Talias a default initalizer
UplinkCoder May 27, 2020
8411bbe
Cast to alias means pass through
UplinkCoder May 29, 2020
45a043c
Allow assignments to alias to go thorugh without making copies or such
UplinkCoder May 29, 2020
fa470be
UFCS for type functions
UplinkCoder May 29, 2020
35aa9f9
fixup rebase
UplinkCoder Jun 19, 2020
ba1fbde
Make setting length work
UplinkCoder Jul 28, 2020
4bf58ab
WIP: is pattern matching expressions in type functions
UplinkCoder Aug 20, 2020
62f3e0d
Adapt to ErrorExp.get()
UplinkCoder Sep 5, 2020
b9f74e0
adjust usage of parameterList
UplinkCoder Sep 5, 2020
d62180b
remove expressionsemantic log
UplinkCoder Sep 10, 2020
723248d
Make UFCS work again
UplinkCoder Sep 10, 2020
eb57b91
Revert "Make UFCS work again"
UplinkCoder Sep 26, 2020
e511c2d
Handle == and : in isExp
UplinkCoder Oct 1, 2020
7950a40
somewhat better intgration of the cast(alias)type
UplinkCoder Oct 2, 2020
76c4cce
Don't ask for abi sizes when there are alias fields inside a struct
UplinkCoder Oct 2, 2020
16519ac
Actually set offset for talias
UplinkCoder Oct 2, 2020
c8030f0
Fix a tspec with static type as opposed to type variable
UplinkCoder Oct 3, 2020
157532d
Allow lone basic types to be passed as primary expressions
UplinkCoder Oct 4, 2020
9d43ccd
Allow creation of tuple from a statically known alias[]
UplinkCoder Oct 6, 2020
27f6673
return false for is(empty type)
UplinkCoder Oct 8, 2020
2666168
Adjust to resolve using out parameters
UplinkCoder Oct 9, 2020
8e69c8d
Rename Talias to Ttype internally change alias initializer from alias…
UplinkCoder Oct 8, 2020
2bbf34e
Fix change in 'fail_compilation/ice12350.d' which would not execute c…
UplinkCoder Oct 9, 2020
e3df99e
Introduce the empty type and use it as return value for __type.init
UplinkCoder Oct 9, 2020
f0fb3f5
When evaluating .stringof of a type variable in a non ctfe context re…
UplinkCoder Oct 9, 2020
2d7e00d
Introduce __type and ∅ and use __type as the type of types instead of…
UplinkCoder Oct 10, 2020
aef3af9
Add empty and __type to valid ctfe values
UplinkCoder Oct 10, 2020
24c7553
Adjust test
UplinkCoder Oct 10, 2020
341e600
Add __traits(identifier, TypeExp) into typefunction handling
UplinkCoder Oct 10, 2020
b2b19bd
Handle __type.init
UplinkCoder Oct 10, 2020
c28b935
Rename ∅ to empty type and allow it in expressions
UplinkCoder Oct 10, 2020
568a374
Any type also all basic types implicitly converts to __type
UplinkCoder Oct 11, 2020
c04ae88
Resolve typeof(type) to __type
UplinkCoder Oct 11, 2020
67e779e
Rename TOK.empty_ to TOK.emptyType_
UplinkCoder Oct 12, 2020
03af0c5
Allow ? : expressions with types
UplinkCoder Oct 13, 2020
f584283
Error if __type escapes into the backend!
UplinkCoder Oct 13, 2020
b57db64
Rename __type to __type__ to avoid clashes with the in.h header
Oct 14, 2020
41d91b9
Disable typeof(type) == __type__ if -sktf is not given
UplinkCoder Oct 14, 2020
a3445f1
Add empty mangle for Tempty
UplinkCoder Oct 13, 2020
ba3789b
Introduce mangle for empty type, cuz otherwise it'll merge, what a bo…
UplinkCoder Oct 19, 2020
5352abe
Introduce __traits(getSuper) for type functions
UplinkCoder Oct 19, 2020
d9b2699
Add TypeExpression to the visited Types
UplinkCoder Oct 26, 2020
9b3ef41
Fix is(type-variable[index-exp])
UplinkCoder Oct 26, 2020
503430c
Adjust tests to new __type__ type
UplinkCoder Nov 16, 2020
2d73e88
double underscore identifiers don't show up in traits(allMembers) ...…
UplinkCoder Jan 4, 2021
dda6128
fix incompatible type error
UplinkCoder Jan 4, 2021
29d3587
Accept typeof(type) only when typefunctions are enabled
UplinkCoder Jan 5, 2021
87121f6
Add test for basic type type invariants
UplinkCoder Jan 5, 2021
7af952f
Make sk_typefunctions a preview swtich
UplinkCoder Jan 5, 2021
5b4a45b
Add __type__ and __emptyType to lexer unittest
UplinkCoder Jan 5, 2021
4889933
Regenerate frontend header
UplinkCoder Jan 5, 2021
30b340d
Fix trailing whitespace and tabs
UplinkCoder Jan 5, 2021
a4483ed
Add TypeExpression, ttype and tempty to astbase.d
UplinkCoder Jan 27, 2021
bd86c3e
Add TOK_type__, TOKemptyType_ to tokens.h
UplinkCoder Jan 27, 2021
514a073
Adjust visitor.h
UplinkCoder Jan 27, 2021
054e8e0
Comment out unused variable
UplinkCoder Jan 27, 2021
a9b34f0
Add typefunction specialized __traits(parent)
UplinkCoder Jan 28, 2021
bab70b1
Add test for typefunction __traits(parent)
UplinkCoder Jan 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/dmd/argtypes_x86.d
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ extern (C++) TypeTuple toArgTypes_x86(Type t)
Type t2 = null;
switch (t.ty)
{
case Ttype:
case Tvoid:
return;
case Tbool:
Expand Down
36 changes: 36 additions & 0 deletions src/dmd/astbase.d
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ struct ASTBase

Tdelegate,
Tnone,

Ttype,
Tempty,

Tvoid,
Tint8,
Tuns8,
Expand Down Expand Up @@ -204,6 +208,7 @@ struct ASTBase
Tuns128,
Ttraits,
Tmixin,
Texp,
TMAX
}

Expand All @@ -219,6 +224,8 @@ struct ASTBase
alias Tenum = ENUMTY.Tenum;
alias Tdelegate = ENUMTY.Tdelegate;
alias Tnone = ENUMTY.Tnone;
alias Ttype = ENUMTY.Ttype;
alias Tempty = ENUMTY.Tempty;
alias Tvoid = ENUMTY.Tvoid;
alias Tint8 = ENUMTY.Tint8;
alias Tuns8 = ENUMTY.Tuns8;
Expand Down Expand Up @@ -253,6 +260,7 @@ struct ASTBase
alias Tuns128 = ENUMTY.Tuns128;
alias Ttraits = ENUMTY.Ttraits;
alias Tmixin = ENUMTY.Tmixin;
alias Texp = ENUMTY.Texp;
alias TMAX = ENUMTY.TMAX;

alias TY = ubyte;
Expand Down Expand Up @@ -2767,6 +2775,9 @@ struct ASTBase
extern (C++) __gshared Type terror; // for error recovery
extern (C++) __gshared Type tnull; // for null type

extern (C++) __gshared Type ttype; // type of types
extern (C++) __gshared Type tempty; // the empty type

extern (C++) __gshared Type tsize_t; // matches size_t alias
extern (C++) __gshared Type tptrdiff_t; // matches ptrdiff_t alias
extern (C++) __gshared Type thash_t; // matches hash_t alias
Expand Down Expand Up @@ -2814,6 +2825,7 @@ struct ASTBase
sizeTy[Tnull] = __traits(classInstanceSize, TypeNull);
sizeTy[Tvector] = __traits(classInstanceSize, TypeVector);
sizeTy[Tmixin] = __traits(classInstanceSize, TypeMixin);
sizeTy[Texp] = __traits(classInstanceSize, TypeExpression);
return sizeTy;
}();

Expand Down Expand Up @@ -3573,6 +3585,7 @@ struct ASTBase
inout(TypeSlice) isTypeSlice() { return ty == Tslice ? cast(typeof(return))this : null; }
inout(TypeNull) isTypeNull() { return ty == Tnull ? cast(typeof(return))this : null; }
inout(TypeMixin) isTypeMixin() { return ty == Tmixin ? cast(typeof(return))this : null; }
inout(TypeExpression) isTypeExpression() { return ty == Texp ? cast(typeof(return))this : null; }
inout(TypeTraits) isTypeTraits() { return ty == Ttraits ? cast(typeof(return))this : null; }
}

Expand Down Expand Up @@ -4530,6 +4543,29 @@ struct ASTBase
}
}

extern (C++) final class TypeExpression : Type
{
Loc loc;
Expression exp;

extern (D) this(const ref Loc loc, Expression exp)
{
super(Texp);
this.loc = loc;
this.exp = exp;
}

override TypeExpression syntaxCopy()
{
return new TypeExpression(loc, exp.syntaxCopy());
}

override void accept(Visitor v)
{
v.visit(this);
}
}

extern (C++) final class TypeIdentifier : TypeQualified
{
Identifier ident;
Expand Down
2 changes: 2 additions & 0 deletions src/dmd/cli.d
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,8 @@ dmd -cov -unittest myprog.d
"'in' contracts of overridden methods must be a superset of parent contract"),
Feature("shortenedMethods", "shortenedMethods",
"allow use of => for methods and top-level functions in addition to lambdas"),
Feature("typefunctions", "sk_typefunctions",
"enables functions to work with type values, also known as Stefan Kochs type functions"),
// DEPRECATED previews
// trigger deprecation message once D repositories don't use this flag anymore
Feature("markdown", "markdown", "enable Markdown replacements in Ddoc", false, false),
Expand Down
9 changes: 9 additions & 0 deletions src/dmd/constfold.d
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,7 @@ UnionExp Cat(Type type, Expression e1, Expression e2)
}
else if ((e1.op == TOK.arrayLiteral || e1.op == TOK.null_) && e1.type.toBasetype().nextOf() && e1.type.toBasetype().nextOf().equals(e2.type))
{
L4:
auto elems = (e1.op == TOK.arrayLiteral)
? copyElements(e1) : new Expressions();
elems.push(e2);
Expand Down Expand Up @@ -1791,8 +1792,16 @@ UnionExp Cat(Type type, Expression e1, Expression e2)
e = ue.exp();
}
}
else if (e1.op == TOK.arrayLiteral && e2.op == TOK.type)
{
// when we have a type here we can just go the regular array cat
goto L4;
}
else
{
//printf("don't know how to deal with exps.ops: {%s, %s}\n", Token.toChars(e1.op), Token.toChars(e2.op));
cantExp(ue);
}
assert(ue.exp().type);
return ue;
}
Expand Down
25 changes: 24 additions & 1 deletion src/dmd/ctfeexpr.d
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ UnionExp copyLiteral(Expression e)
emplaceExp!(UnionExp)(&ue, e);
return ue;
}
if (e.op == TOK.type)
{
emplaceExp!(TypeExp)(&ue, e.loc, e.type);
return ue;
}
e.error("CTFE internal error: literal `%s`", e.toChars());
assert(0);
}
Expand All @@ -438,6 +443,14 @@ Expression paintTypeOntoLiteral(Type type, Expression lit)

Expression paintTypeOntoLiteral(UnionExp* pue, Type type, Expression lit)
{
// painting to alias is a no-op
if (type.ty == Ttype)
{
auto nlit = lit.copy();
//nlit.type = Type.talias;
return nlit;
}

if (lit.type.equals(type))
return lit;
*pue = paintTypeOntoLiteralCopy(type, lit);
Expand Down Expand Up @@ -1574,6 +1587,11 @@ Expression ctfeCast(UnionExp* pue, const ref Loc loc, Type type, Type to, Expres
return paintTypeOntoLiteral(pue, to, e);
}

if (to.ty == Ttype)
{
return e;
}

if (e.op == TOK.null_)
return paint();

Expand All @@ -1600,7 +1618,7 @@ Expression ctfeCast(UnionExp* pue, const ref Loc loc, Type type, Type to, Expres
return paint();

Expression r;
if (e.type.equals(type) && type.equals(to))
if (((type is to && e.type is type) || (e.type.equals(type) && type.equals(to))))
{
// necessary not to change e's address for pointer comparisons
r = e;
Expand Down Expand Up @@ -1903,6 +1921,11 @@ bool isCtfeValueValid(Expression newval)
case TOK.void_:
return true; // uninitialized value

case TOK._type__:
case TOK.emptyType_:
case TOK.scope_:
return global.params.sk_typefunctions ? true : false;

default:
newval.error("CTFE internal error: illegal CTFE value `%s`", newval.toChars());
return false;
Expand Down
17 changes: 17 additions & 0 deletions src/dmd/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ Expression implicitCastTo(Expression e, Scope* sc, Type t)
{
//printf("Expression.implicitCastTo(%s of type %s) => %s\n", e.toChars(), e.type.toChars(), t.toChars());

if (t.ty == Ttype)
{
// casts to Ttype just create a new castExp.
result = new CastExp(e.loc, e, t);
result.type = t;
return ;
}

if (const match = e.implicitConvTo(t))
{
if (match == MATCH.constant && (e.type.constConv(t) || !e.isLvalue() && e.type.equivalent(t)))
Expand Down Expand Up @@ -1437,8 +1445,17 @@ MATCH implicitConvTo(Expression e, Type t)
if (tb.ty == Tpointer && e.e1.op == TOK.string_)
e.e1.accept(this);
}

override void visit(TypeExp e)
{
// TODO FIXME this should work
// MATCH match = e.type.implicitConvTo(t);
if (t.ty == Ttype)
result = MATCH.convert;
}
}


scope ImplicitConvTo v = new ImplicitConvTo(t);
e.accept(v);
return v.result;
Expand Down
4 changes: 2 additions & 2 deletions src/dmd/declaration.d
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ extern (C++) class VarDeclaration : Declaration
const sz = t.size(loc);
assert(sz != SIZE_INVALID && sz < uint.max);
uint memsize = cast(uint)sz; // size of member
uint memalignsize = target.fieldalign(t); // size of member for alignment purposes
uint memalignsize = (t.ty == Ttype) ? 1 : target.fieldalign(t); // size of member for alignment purposes
offset = AggregateDeclaration.placeField(
poffset,
memsize, memalignsize, alignment,
Expand Down Expand Up @@ -1336,7 +1336,7 @@ extern (C++) class VarDeclaration : Declaration
*/
final bool isCTFE()
{
return (storage_class & STC.ctfe) != 0; // || !isDataseg();
return ((storage_class & STC.ctfe) != 0) || isTypeType(type);
}

final bool isOverlappedWith(VarDeclaration v)
Expand Down
Loading