Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Type predicates: implemented helper functions to append / filter out type predicate hashes in identities. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
d40e6470bf3d96f9491088e1a3ddbd96 |
| User & Date: | zlodo 2021-10-26 18:43:49.313 |
Context
|
2021-10-27
| ||
| 20:55 | Parser: when building a function, if its parent identity depends on type predicates captured by template vars, build it as a template function instead. check-in: 45078c42df user: zlodo tags: trunk | |
|
2021-10-26
| ||
| 18:43 | Type predicates: implemented helper functions to append / filter out type predicate hashes in identities. check-in: d40e6470bf user: zlodo tags: trunk | |
|
2021-10-25
| ||
| 19:34 | Type predicates: store the expressions as an array of values, which avoids unecessary conversions and results in the inclusion of the CIR from the expressions in the hash check-in: 996d8d9686 user: zlodo tags: trunk | |
Changes
Changes to bs/builtins/types/basic.cpp.
| ︙ | ︙ | |||
54 55 56 57 58 59 60 |
}
optional< bool > Bridge< bool >::FromValue( const Value& v )
{
if( v.type() != Type() )
return nullopt;
| | | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
}
optional< bool > Bridge< bool >::FromValue( const Value& v )
{
if( v.type() != Type() )
return nullopt;
const auto* pint = get_if< uint64_t >( &v.val() );
if( !pint )
return nullopt;
return *pint;
}
// Integers
|
| ︙ | ︙ | |||
93 94 95 96 97 98 99 |
}
optional< char32_t > Bridge< char32_t >::FromValue( const Value& v )
{
if( v.type() != Type() )
return nullopt;
| | | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
}
optional< char32_t > Bridge< char32_t >::FromValue( const Value& v )
{
if( v.type() != Type() )
return nullopt;
return get< uint64_t >( v.val() );
}
// strings
const Term& Bridge< string >::Type()
{
static auto type = ValueToEIR( Value( TypeType(), MkStdType( TSID( ct_type ), TSID( ct_string ) ) ) );
return type;
|
| ︙ | ︙ |
Changes to bs/builtins/types/func/func.cpp.
| ︙ | ︙ | |||
248 249 250 251 252 253 254 |
auto result = Decompose( v.val(),
Vec(
Lit( "func"_sid ),
Val< void* >(),
SubTerm(), // return type
SubTerm(), // param types
Val< ptr< void > >(), // verif infos
| | | | 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
auto result = Decompose( v.val(),
Vec(
Lit( "func"_sid ),
Val< void* >(),
SubTerm(), // return type
SubTerm(), // param types
Val< ptr< void > >(), // verif infos
Val< uint64_t >() // flags
)
);
if( !result )
{
// Try to decode it as an inrinsic function type
auto result = Decompose( v.val(),
Vec(
Lit( "func"_sid ),
Lit( "intrinsic"_sid ),
SubTerm(), // return type
SubTerm(), // param types
Val< ptr< void > >(), // verif infos
Val< uint64_t >() // flags
)
);
if( !result )
return nullopt;
auto&& [rtype, params, vinf, flags] = *result;
|
| ︙ | ︙ |
Changes to bs/builtins/types/localvar/localvar.cpp.
| ︙ | ︙ | |||
269 270 271 272 273 274 275 |
// typechecking abstract arguments while resolving function typed parameters
return LocalVar( move( t->type() ) );
}
auto result = Decompose( v.val(),
Vec(
Val< StringId >(),
| | | 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
// typechecking abstract arguments while resolving function typed parameters
return LocalVar( move( t->type() ) );
}
auto result = Decompose( v.val(),
Vec(
Val< StringId >(),
Val< uint64_t >()
)
);
if( !result )
return nullopt;
auto&& [name,index] = *result;
|
| ︙ | ︙ |
Changes to bs/builtins/types/predicates/predicates.cpp.
| ︙ | ︙ | |||
95 96 97 98 99 100 101 102 |
// verify that the verification statements are satisfiable
verify::Condition vsv( c );
if( !vsv.addConditionsList( tp.m_predicates ) )
return false;
return vsv.verify();
}
}
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
// verify that the verification statements are satisfiable
verify::Condition vsv( c );
if( !vsv.addConditionsList( tp.m_predicates ) )
return false;
return vsv.verify();
}
Term AppendPredicatesHashToIdentity( const Term& identity, size_t hash )
{
return AppendToVectorTerm( identity, VEC( TSID( pred_hash ), TERM( hash ) ) );
}
Term StripPredicateHashesFromIdentity( const Term& identity )
{
const auto& vec = *get< pvec >( identity );
auto result = make_shared< Vector >();
result->reserve( vec.terms().size() );
for( auto&& t : vec.terms() )
{
auto decomp = Decompose( t,
Vec(
Lit( "pred_hash"_sid ),
Val< uint64_t >()
)
);
if( decomp )
continue;
result->append( t );
}
return result;
}
}
|
Changes to bs/builtins/types/predicates/predicates.h.
| ︙ | ︙ | |||
8 9 10 11 12 13 14 15 16 17 |
extern const Term& EmptyPredicates();
extern optional< ptr< TypePredicates > > GetTypePredicates( const Value& t );
extern Term InjectPredicatesIntoStdType( const Term& t, const ptr< TypePredicates >& predicates );
extern bool ParseTypePredicates( const Context& c, const Value& type );
extern bool ParseTypePredicates( const Context& c, TypePredicates& tp );
}
#endif
| > > > | 8 9 10 11 12 13 14 15 16 17 18 19 20 |
extern const Term& EmptyPredicates();
extern optional< ptr< TypePredicates > > GetTypePredicates( const Value& t );
extern Term InjectPredicatesIntoStdType( const Term& t, const ptr< TypePredicates >& predicates );
extern bool ParseTypePredicates( const Context& c, const Value& type );
extern bool ParseTypePredicates( const Context& c, TypePredicates& tp );
extern Term AppendPredicatesHashToIdentity( const Term& identity, size_t hash );
extern Term StripPredicateHashesFromIdentity( const Term& identity );
}
#endif
|
Changes to bs/builtins/types/runtime/array.cpp.
| ︙ | ︙ | |||
40 41 42 43 44 45 46 |
{
auto result = Decompose( v.val(),
Vec(
Lit( "rt_type"_sid ),
SubTerm(),
Val< void* >(),
Lit( "array"_sid ),
| | | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
{
auto result = Decompose( v.val(),
Vec(
Lit( "rt_type"_sid ),
SubTerm(),
Val< void* >(),
Lit( "array"_sid ),
Val< uint64_t >(),
SubTerm()
)
);
if( !result )
return nullopt;
|
| ︙ | ︙ |
Changes to bs/builtins/types/runtime/array.h.
1 2 3 4 5 6 7 8 9 10 |
#ifndef GOOSE_BUILTINS_TYPES_RUNTIME_ARRAY_H
#define GOOSE_BUILTINS_TYPES_RUNTIME_ARRAY_H
namespace goose::builtins
{
extern void SetupRuntimeArrayType( Env& e );
struct ArrayType
{
template< typename T >
| | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#ifndef GOOSE_BUILTINS_TYPES_RUNTIME_ARRAY_H
#define GOOSE_BUILTINS_TYPES_RUNTIME_ARRAY_H
namespace goose::builtins
{
extern void SetupRuntimeArrayType( Env& e );
struct ArrayType
{
template< typename T >
ArrayType( T&& containedType, uint64_t count ) :
m_containedType( forward< T >( containedType ) ),
m_count( count )
{}
Term m_containedType;
uint64_t m_count = 1;
};
extern llvm::Type* GetLLVMType( const ArrayType& a );
}
namespace goose::eir
{
|
| ︙ | ︙ |
Changes to bs/builtins/types/runtime/basic.cpp.
| ︙ | ︙ | |||
140 141 142 143 144 145 146 |
auto result = Decompose( v.val(),
Vec(
Lit( "rt_type"_sid ),
SubTerm(),
Val< void* >(),
Lit( "integer"_sid ),
Vec(
| | | | 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
auto result = Decompose( v.val(),
Vec(
Lit( "rt_type"_sid ),
SubTerm(),
Val< void* >(),
Lit( "integer"_sid ),
Vec(
Val< uint64_t >(),
Val< uint64_t >()
)
)
);
if( !result )
return nullopt;
|
| ︙ | ︙ |
Changes to bs/builtins/types/runtime/record.cpp.
| ︙ | ︙ | |||
70 71 72 73 74 75 76 |
{
auto result = Decompose( v.val(),
Vec(
Lit( "rt_type"_sid ),
SubTerm(),
Val< void* >(),
Lit( "record"_sid ),
| | | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
{
auto result = Decompose( v.val(),
Vec(
Lit( "rt_type"_sid ),
SubTerm(),
Val< void* >(),
Lit( "record"_sid ),
Val< uint64_t >(),
Val< pvec >()
)
);
if( !result )
return nullopt;
|
| ︙ | ︙ |
Changes to bs/builtins/types/template/tfunctype.cpp.
| ︙ | ︙ | |||
68 69 70 71 72 73 74 |
Vec(
Lit( "texpr"_sid ),
Lit( "tfunc"_sid ),
SubTerm(), // return type
SubTerm(), // param types
Val< ptr< void > >(), // verif stmts toks
Val< ptr< void > >(), // verif stmts toks
| | | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
Vec(
Lit( "texpr"_sid ),
Lit( "tfunc"_sid ),
SubTerm(), // return type
SubTerm(), // param types
Val< ptr< void > >(), // verif stmts toks
Val< ptr< void > >(), // verif stmts toks
Val< uint64_t >() // intrinsic flag
)
);
if( !result )
return nullopt;
auto&& [rtype, params, preToks, postToks, intrinsic] = *result;
|
| ︙ | ︙ |
Changes to bs/codegen/mangle.cpp.
| ︙ | ︙ | |||
69 70 71 72 73 74 75 |
{
return visit( [&]( auto&& t )
{
return mangle( t );
}, t );
}
| | | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
{
return visit( [&]( auto&& t )
{
return mangle( t );
}, t );
}
bool mangle( uint64_t integer )
{
m_mangled << 'i' << integer;
return true;
}
// Locations shouldn't be included in the mangling, but
// should not cause it to fail either.
|
| ︙ | ︙ |
Changes to bs/eir/compare.cpp.
| ︙ | ︙ | |||
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
return *l == *r;
else if constexpr( is_same_v< LocationId, T > )
return true;
else if constexpr( is_same_v< ptr< void >, T > )
return true;
else if constexpr( is_same_v< void*, T > )
return true;
else
return l == r;
}, lhs );
}
bool operator!=( const Term& lhs, const Term& rhs )
{
| > > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
return *l == *r;
else if constexpr( is_same_v< LocationId, T > )
return true;
else if constexpr( is_same_v< ptr< void >, T > )
return true;
else if constexpr( is_same_v< void*, T > )
return true;
else if constexpr( is_same_v< APSInt, T >)
return l.isSigned() == r.isSigned() && l.getBitWidth() == r.getBitWidth() && l == r;
else
return l == r;
}, lhs );
}
bool operator!=( const Term& lhs, const Term& rhs )
{
|
| ︙ | ︙ |
Changes to bs/eir/term.h.
| ︙ | ︙ | |||
41 42 43 44 45 46 47 |
private:
StringId m_name;
ptr< STerm > m_kind = make_shared< STerm >();
};
using Term = variant
<
| | | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
private:
StringId m_name;
ptr< STerm > m_kind = make_shared< STerm >();
};
using Term = variant
<
uint64_t,
LocationId,
string,
StringId,
Delimiter,
Hole,
AnyTerm,
VecOfLength,
|
| ︙ | ︙ |
Changes to bs/eir/trie.h.
| ︙ | ︙ | |||
10 11 12 13 14 15 16 |
template< typename T, typename U >
struct ValueTrieNode
{
unordered_map< T, U > m_branches;
};
template< typename U >
| | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
template< typename T, typename U >
struct ValueTrieNode
{
unordered_map< T, U > m_branches;
};
template< typename U >
struct TrieNode< uint64_t, U > : public ValueTrieNode< uint64_t, U >
{};
template< typename U >
struct TrieNode< LocationId, U >
{
U m_next;
};
|
| ︙ | ︙ | |||
104 105 106 107 108 109 110 |
template< typename U >
class Trie
{
public:
using BranchesTuple = tuple
<
| | | 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
template< typename U >
class Trie
{
public:
using BranchesTuple = tuple
<
ptr< TrieNode< uint64_t, U > >,
ptr< TrieNode< LocationId, U > >,
ptr< TrieNode< string, U > >,
ptr< TrieNode< StringId, U > >,
ptr< TrieNode< Delimiter, U > >,
ptr< TrieNode< Hole, U > >,
ptr< TrieNode< AnyTerm, U > >,
ptr< TrieNode< VecOfLength, U > >,
|
| ︙ | ︙ |
Changes to bs/eir/value.cpp.
| ︙ | ︙ | |||
8 9 10 11 12 13 14 |
}
bool Value::isMetaType() const
{
auto result = Decompose( type(),
Vec(
Lit( "type"_sid ),
| | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
}
bool Value::isMetaType() const
{
auto result = Decompose( type(),
Vec(
Lit( "type"_sid ),
Val< uint64_t >(),
Val< LocationId >()
)
);
return !!result;
}
|
| ︙ | ︙ | |||
45 46 47 48 49 50 51 |
{
if( v.isConstant() )
{
// Special case for type's type
if( v.isMetaType() )
{
auto result = Decompose( v.val(),
| | | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
{
if( v.isConstant() )
{
// Special case for type's type
if( v.isMetaType() )
{
auto result = Decompose( v.val(),
Val< uint64_t >()
);
if( result && result->get() > 0 )
{
return VEC( TSID( type ), TERM( result->get() ),
static_cast< LocationId >( v.locationId() ) );
}
|
| ︙ | ︙ | |||
70 71 72 73 74 75 76 |
optional< Value > EIRToValue( const Term& t )
{
// Special case for type's type
auto typedecomp = Decompose( t,
Vec(
Lit( "type"_sid ),
| | | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
optional< Value > EIRToValue( const Term& t )
{
// Special case for type's type
auto typedecomp = Decompose( t,
Vec(
Lit( "type"_sid ),
Val< uint64_t >(),
Val< LocationId >()
)
);
if( typedecomp )
{
auto&& [universeIndex, loc] = *typedecomp;
|
| ︙ | ︙ |
Changes to bs/g0api/extensibility/eir.cpp.
| ︙ | ︙ | |||
73 74 75 76 77 78 79 |
DefineConstant( e, "DelimiterCloseParen"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( Delimiter::CloseParen ) ) ) );
DefineConstant( e, "DelimiterCloseBrace"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( Delimiter::CloseBrace ) ) ) );
DefineConstant( e, "DelimiterCloseBracket"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( Delimiter::CloseBracket ) ) ) );
// This enum must match the order of the types in the Term variant.
enum class TermType
{
| | | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
DefineConstant( e, "DelimiterCloseParen"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( Delimiter::CloseParen ) ) ) );
DefineConstant( e, "DelimiterCloseBrace"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( Delimiter::CloseBrace ) ) ) );
DefineConstant( e, "DelimiterCloseBracket"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( Delimiter::CloseBracket ) ) ) );
// This enum must match the order of the types in the Term variant.
enum class TermType
{
UInt64,
LocationId,
String,
StringId,
Delimiter,
Hole,
AnyTerm,
VecOfLength,
Vec,
BigInt,
FixedInt,
Internal
};
DefineConstant( e, "TermTypeUInt64"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( TermType::UInt64 ) ) ) );
DefineConstant( e, "TermTypeLocationId"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( TermType::LocationId ) ) ) );
DefineConstant( e, "TermTypeString"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( TermType::String ) ) ) );
DefineConstant( e, "TermTypeStringId"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( TermType::StringId ) ) ) );
DefineConstant( e, "TermTypeDelimiter"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( TermType::Delimiter ) ) ) );
DefineConstant( e, "TermTypeHole"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( TermType::Hole ) ) ) );
DefineConstant( e, "TermTypeAnyTerm"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( TermType::AnyTerm ) ) ) );
DefineConstant( e, "TermTypeVecOfLength"_sid, ValueToEIR( ToValue( static_cast< uint8_t >( TermType::VecOfLength ) ) ) );
|
| ︙ | ︙ | |||
112 113 114 115 116 117 118 |
} );
////////////////////////////
// MkTerm overloads
////////////////////////////
auto MkTerm = CreateOverloadSet( e, "MkTerm"_sid );
| | | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
} );
////////////////////////////
// MkTerm overloads
////////////////////////////
auto MkTerm = CreateOverloadSet( e, "MkTerm"_sid );
RegisterMkTermOverload< uint64_t >( e, MkTerm );
RegisterMkTermOverload< TypeWrapper< LocationId > >( e, MkTerm );
RegisterMkTermOverload< string >( e, MkTerm );
RegisterMkTermOverload< TypeWrapper< StringId > >( e, MkTerm );
RegisterBuiltinFunc< TypeWrapper< Term > ( uint8_t ) >( e, "MkDelimiterTerm"_sid,
[]( uint8_t d ) -> TypeWrapper< Term >
{
|
| ︙ | ︙ | |||
134 135 136 137 138 139 140 |
RegisterMkTermOverload< BigInt >( e, MkTerm );
RegisterMkTermOverload< TypeWrapper< APSInt > >( e, MkTerm );
////////////////////////////
// GetTermValue overloads
////////////////////////////
auto GetTermValue = CreateOverloadSet( e, "GetTermValue"_sid );
| | | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
RegisterMkTermOverload< BigInt >( e, MkTerm );
RegisterMkTermOverload< TypeWrapper< APSInt > >( e, MkTerm );
////////////////////////////
// GetTermValue overloads
////////////////////////////
auto GetTermValue = CreateOverloadSet( e, "GetTermValue"_sid );
RegisterGetTermValueOverload< uint64_t >( e, GetTermValue );
RegisterGetTermValueOverload< TypeWrapper< LocationId > >( e, GetTermValue );
RegisterGetTermValueOverload< string >( e, GetTermValue );
RegisterGetTermValueOverload< TypeWrapper< StringId > >( e, GetTermValue );
RegisterBuiltinFunc< bool ( TypeWrapper< Term >, TermRef< uint8_t > ) >( e, "GetDelimiterTermValue"_sid,
[]( const TypeWrapper< Term >& t, TermRef< uint8_t >& tref )
{
|
| ︙ | ︙ |
Changes to bs/parse/parser.cpp.
| ︙ | ︙ | |||
130 131 132 133 134 135 136 |
bool Parser::parsePrefix( const BigInt& intlit, uint32_t )
{
auto tok = m_resolver->consume();
pushValue( ToValue( intlit ).setLocationId( tok->second ) );
return true;
}
| | | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
bool Parser::parsePrefix( const BigInt& intlit, uint32_t )
{
auto tok = m_resolver->consume();
pushValue( ToValue( intlit ).setLocationId( tok->second ) );
return true;
}
bool Parser::parsePrefix( uint64_t charlit, uint32_t )
{
auto tok = m_resolver->consume();
pushValue( ToValue( static_cast< char32_t >( charlit ) ).setLocationId( tok->second ) );
return true;
}
bool Parser::parsePrefix( const string& strlit, uint32_t )
|
| ︙ | ︙ |
Changes to bs/parse/parser.h.
| ︙ | ︙ | |||
105 106 107 108 109 110 111 |
// Default parseInfix overload
template< typename T >
bool parseInfix( const T& t, uint32_t );
// Literals
bool parsePrefix( const BigInt& intlit, uint32_t );
| | | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
// Default parseInfix overload
template< typename T >
bool parseInfix( const T& t, uint32_t );
// Literals
bool parsePrefix( const BigInt& intlit, uint32_t );
bool parsePrefix( uint64_t charlit, uint32_t );
bool parsePrefix( const string& strlit, uint32_t );
// Unresolved identifiers
bool parsePrefix( StringId strid, uint32_t );
optional< uint32_t > getPrecedence( const Term&, StringId strid );
bool parseInfix( StringId strid, uint32_t );
|
| ︙ | ︙ |