1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Added comptype test

This commit is contained in:
Brian Fiete 2021-01-16 06:26:55 -08:00
parent 83069fa216
commit 8435caf340
8 changed files with 87 additions and 47 deletions

View file

@ -2912,6 +2912,9 @@ BfType* BfExprEvaluator::BindGenericType(BfAstNode* node, BfType* bindType)
if (!bindType->IsGenericParam())
return bindType;
if (genericTypeBindings == NULL)
return bindType;
(*genericTypeBindings)[nodeId] = bindType;
return bindType;
}
@ -5338,6 +5341,10 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance*
// This either generated an error already or this is just the non-const type check pass for a comptime-only method
doConstReturn = true;
}
else if ((mBfEvalExprFlags & BfEvalExprFlags_DisallowComptime) != 0)
{
doConstReturn = true;
}
else
{
CeEvalFlags evalFlags = CeEvalFlags_None;

View file

@ -2890,6 +2890,7 @@ BfError* BfModule::Fail(const StringImpl& error, BfAstNode* refNode, bool isPers
return true;
};
bool hadMethodInstance = false;
if (mCurMethodState != NULL)
{
auto checkMethodState = mCurMethodState;
@ -2902,12 +2903,14 @@ BfError* BfModule::Fail(const StringImpl& error, BfAstNode* refNode, bool isPers
continue;
}
hadMethodInstance = true;
if (!_CheckMethodInstance(methodInstance))
return NULL;
checkMethodState = checkMethodState->mPrevMethodState;
}
}
else if (mCurMethodInstance != NULL)
if ((!hadMethodInstance) && (mCurMethodInstance != NULL))
{
if (!_CheckMethodInstance(mCurMethodInstance))
return NULL;
@ -7225,7 +7228,11 @@ void BfModule::ResolveGenericParamConstraints(BfGenericParamInstance* genericPar
bfAutocomplete->CheckTypeRef(constraintTypeRef, true);
//TODO: Constraints may refer to other generic params (of either type or method)
// TO allow resolution, perhaps move this generic param initalization into GetMethodInstance (passing a genericPass bool)
auto constraintType = ResolveTypeRef(constraintTypeRef, BfPopulateType_Declaration, BfResolveTypeRefFlag_AllowGenericMethodParamConstValue);
BfResolveTypeRefFlags resolveFlags = BfResolveTypeRefFlag_AllowGenericMethodParamConstValue;
if (isUnspecialized)
resolveFlags = (BfResolveTypeRefFlags)(resolveFlags | BfResolveTypeRefFlag_DisallowComptime);
auto constraintType = ResolveTypeRef(constraintTypeRef, BfPopulateType_Declaration, resolveFlags);
if (constraintType != NULL)
{
if ((constraintDef->mGenericParamFlags & BfGenericParamFlag_Const) != 0)
@ -17881,8 +17888,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
}
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, mWantsIRIgnoreWrites || methodInstance->mIsUnspecialized);
bool ignoreWrites = mBfIRBuilder->mIgnoreWrites;
if ((HasCompiledOutput()) && (!mBfIRBuilder->mIgnoreWrites))
{
BF_ASSERT(!methodInstance->mIRFunction.IsFake() || (methodInstance->GetImportCallKind() != BfImportCallKind_None));
@ -17953,6 +17959,9 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
auto methodDef = methodInstance->mMethodDef;
auto methodDeclaration = methodDef->GetMethodDeclaration();
if ((methodDef->mHasComptime) && (!mIsComptimeModule))
mBfIRBuilder->mIgnoreWrites = true;
if ((methodInstance->mIsReified) && (methodInstance->mVirtualTableIdx != -1))
{
// If we reify a virtual method in a HotCompile then we need to make sure the type data gets written out
@ -18320,7 +18329,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
}
}
bool wantsDIData = (mBfIRBuilder->DbgHasInfo()) && (!methodDef->IsEmptyPartial()) && (!mCurMethodInstance->mIsUnspecialized) && (mHasFullDebugInfo);
bool wantsDIData = (mBfIRBuilder->DbgHasInfo()) && (!methodDef->IsEmptyPartial()) && (!mBfIRBuilder->mIgnoreWrites) && (mHasFullDebugInfo);
if (methodDef->mMethodType == BfMethodType_Mixin)
wantsDIData = false;
@ -19709,7 +19718,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
mBfIRBuilder->MoveBlockToEnd(mCurMethodState->mIRExitBlock);
mBfIRBuilder->SetInsertPoint(mCurMethodState->mIRExitBlock);
if (!mCurMethodState->mDIRetVal)
if ((!mCurMethodState->mDIRetVal) && (wantsDIData))
CreateDIRetVal();
}
@ -19807,8 +19816,8 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
}
// Avoid linking any internal funcs that were just supposed to be comptime-accessible
if ((methodDef->mHasComptime) && (!mIsComptimeModule))
wantsRemoveBody = true;
/*if ((methodDef->mHasComptime) && (!mIsComptimeModule))
wantsRemoveBody = true;*/
if ((hasExternSpecifier) && (!skipBody))
{

View file

@ -73,9 +73,10 @@ enum BfEvalExprFlags
BfEvalExprFlags_StringInterpolateFormat = 0x20000,
BfEvalExprFlags_NoLookupError = 0x40000,
BfEvalExprFlags_Comptime = 0x80000,
BfEvalExprFlags_InCascade = 0x100000,
BfEvalExprFlags_InferReturnType = 0x200000,
BfEvalExprFlags_WasMethodRef = 0x400000
BfEvalExprFlags_DisallowComptime = 0x100000,
BfEvalExprFlags_InCascade = 0x200000,
BfEvalExprFlags_InferReturnType = 0x400000,
BfEvalExprFlags_WasMethodRef = 0x800000
};
enum BfCastFlags

View file

@ -9350,7 +9350,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
}
BfResolvedTypeSet::LookupContext lookupCtx;
lookupCtx.mResolveFlags = (BfResolveTypeRefFlags)(resolveFlags & (BfResolveTypeRefFlag_NoCreate | BfResolveTypeRefFlag_IgnoreLookupError));
lookupCtx.mResolveFlags = (BfResolveTypeRefFlags)(resolveFlags & (BfResolveTypeRefFlag_NoCreate | BfResolveTypeRefFlag_IgnoreLookupError | BfResolveTypeRefFlag_DisallowComptime));
lookupCtx.mRootTypeRef = typeRef;
lookupCtx.mRootTypeDef = typeDef;
lookupCtx.mModule = this;

View file

@ -3427,10 +3427,21 @@ int BfResolvedTypeSet::Hash(BfTypeReference* typeRef, LookupContext* ctx, BfHash
SetAndRestoreValue<bool> ignoreWrites(ctx->mModule->mBfIRBuilder->mIgnoreWrites, true);
SetAndRestoreValue<bool> allowUninitReads(ctx->mModule->mCurMethodState->mAllowUinitReads, true);
BfEvalExprFlags exprFlags = BfEvalExprFlags_None;
if ((ctx->mResolveFlags & BfResolveTypeRefFlag_DisallowComptime) != 0)
{
exprFlags = (BfEvalExprFlags)(exprFlags | BfEvalExprFlags_DisallowComptime);
}
if (exprModTypeRef->mToken->mToken == BfToken_Comptype)
result = ctx->mModule->CreateValueFromExpression(exprModTypeRef->mTarget, ctx->mModule->ResolveTypeDef(ctx->mModule->mCompiler->mTypeTypeDef), BfEvalExprFlags_Comptime);
{
exprFlags = (BfEvalExprFlags)(exprFlags | BfEvalExprFlags_Comptime);
result = ctx->mModule->CreateValueFromExpression(exprModTypeRef->mTarget, ctx->mModule->ResolveTypeDef(ctx->mModule->mCompiler->mTypeTypeDef), exprFlags);
}
else
{
result = ctx->mModule->CreateValueFromExpression(exprModTypeRef->mTarget);
}
}
if ((result) && (exprModTypeRef->mToken->mToken == BfToken_Comptype))

View file

@ -31,7 +31,8 @@ enum BfResolveTypeRefFlags
BfResolveTypeRefFlag_Attribute = 0x100,
BfResolveTypeRefFlag_NoReify = 0x200,
BfResolveTypeRefFlag_NoCreate = 0x400,
BfResolveTypeRefFlag_NoWarnOnMut = 0x800
BfResolveTypeRefFlag_NoWarnOnMut = 0x800,
BfResolveTypeRefFlag_DisallowComptime = 0x1000
};
enum BfTypeNameFlags : uint16