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

Fixed some var usage

This commit is contained in:
Brian Fiete 2019-11-02 06:02:36 -07:00
parent 54fa1e0811
commit e1656865bb
3 changed files with 24 additions and 37 deletions

View file

@ -794,12 +794,12 @@ BfModule::BfModule(BfContext* context, const StringImpl& moduleName)
mModuleOptions = NULL; mModuleOptions = NULL;
mLastUsedRevision = -1; mLastUsedRevision = -1;
mUsedSlotCount = -1; mUsedSlotCount = -1;
mIsReified = true; mIsReified = true;
mReifyQueued = false; mReifyQueued = false;
mIsSpecialModule = false; mIsSpecialModule = false;
mIsScratchModule = false; mIsScratchModule = false;
mIsSpecializedMethodModuleRoot = false; // There may be mNextAltModules extending from this mIsSpecializedMethodModuleRoot = false; // There may be mNextAltModules extending from this
mHadBuildError = false; mHadBuildError = false;
mHadBuildWarning = false; mHadBuildWarning = false;
mIgnoreErrors = false; mIgnoreErrors = false;
@ -1098,7 +1098,7 @@ void BfModule::EnsureIRBuilder(bool dbgVerifyCodeGen)
// code as we walk the AST // code as we walk the AST
//mBfIRBuilder->mDbgVerifyCodeGen = true; //mBfIRBuilder->mDbgVerifyCodeGen = true;
if ( if (
(mModuleName == "-") (mModuleName == "IDE_ui_LaunchDialog")
//|| (mModuleName == "System_Internal") //|| (mModuleName == "System_Internal")
//|| (mModuleName == "vdata") //|| (mModuleName == "vdata")
//|| (mModuleName == "Hey_Dude_Bro_TestClass") //|| (mModuleName == "Hey_Dude_Bro_TestClass")
@ -1149,7 +1149,7 @@ void BfModule::StartNewRevision(RebuildKind rebuildKind, bool force)
return; return;
mHadBuildError = false; mHadBuildError = false;
mHadBuildWarning = false; mHadBuildWarning = false;
mExtensionCount = 0; mExtensionCount = 0;
mRevision = mCompiler->mRevision; mRevision = mCompiler->mRevision;
mRebuildIdx++; mRebuildIdx++;
@ -2441,12 +2441,6 @@ void BfModule::SetElementType(BfAstNode* astNode, BfSourceElementType elementTyp
} }
} }
void BfModule::SetHadVarUsage()
{
mHadVarUsage = true;
mHadBuildError = true;
}
BfError* BfModule::Fail(const StringImpl& error, BfAstNode* refNode, bool isPersistent) BfError* BfModule::Fail(const StringImpl& error, BfAstNode* refNode, bool isPersistent)
{ {
BP_ZONE("BfModule::Fail"); BP_ZONE("BfModule::Fail");
@ -3339,8 +3333,7 @@ BfType* BfModule::ResolveVarFieldType(BfTypeInstance* typeInstance, BfFieldInsta
if ((!field->mIsStatic) && (typeDef->mIsStatic)) if ((!field->mIsStatic) && (typeDef->mIsStatic))
{ {
AssertErrorState(); AssertErrorState();
SetHadVarUsage();
return GetPrimitiveType(BfTypeCode_Var); return GetPrimitiveType(BfTypeCode_Var);
} }
@ -3359,8 +3352,7 @@ BfType* BfModule::ResolveVarFieldType(BfTypeInstance* typeInstance, BfFieldInsta
SetAndRestoreValue<bool> prevIgnoreError(fieldModule->mIgnoreErrors, false); SetAndRestoreValue<bool> prevIgnoreError(fieldModule->mIgnoreErrors, false);
fieldModule->Fail(StrFormat("Field '%s.%s' creates a type inference cycle", TypeToString(fieldOwner).c_str(), fieldDef->mName.c_str()), fieldDef->mTypeRef, true); fieldModule->Fail(StrFormat("Field '%s.%s' creates a type inference cycle", TypeToString(fieldOwner).c_str(), fieldDef->mName.c_str()), fieldDef->mTypeRef, true);
} }
SetHadVarUsage();
return GetPrimitiveType(BfTypeCode_Var); return GetPrimitiveType(BfTypeCode_Var);
} }
} }
@ -3373,8 +3365,7 @@ BfType* BfModule::ResolveVarFieldType(BfTypeInstance* typeInstance, BfFieldInsta
if ((field->mInitializer == NULL) && (!isDeclType)) if ((field->mInitializer == NULL) && (!isDeclType))
{ {
if ((field->mTypeRef->IsA<BfVarTypeReference>()) || (field->mTypeRef->IsA<BfLetTypeReference>())) if ((field->mTypeRef->IsA<BfVarTypeReference>()) || (field->mTypeRef->IsA<BfLetTypeReference>()))
Fail("Implicitly-typed fields must be initialized", field->GetRefNode()); Fail("Implicitly-typed fields must be initialized", field->GetRefNode());
SetHadVarUsage();
return GetPrimitiveType(BfTypeCode_Var); return GetPrimitiveType(BfTypeCode_Var);
} }
@ -9855,6 +9846,11 @@ BfTypedValue BfModule::LoadValue(BfTypedValue typedValue, BfAstNode* refNode, bo
BfIRValue loadedVal = typedValue.mValue; BfIRValue loadedVal = typedValue.mValue;
if (loadedVal) if (loadedVal)
{ {
if (typedValue.mType->IsVar())
{
return BfTypedValue(loadedVal, typedValue.mType, false);
}
/*if (isVolatile) /*if (isVolatile)
mBfIRBuilder->CreateFence(BfIRFenceType_AcquireRelease);*/ mBfIRBuilder->CreateFence(BfIRFenceType_AcquireRelease);*/
PopulateType(typedValue.mType, BfPopulateType_Data); PopulateType(typedValue.mType, BfPopulateType_Data);
@ -11551,6 +11547,11 @@ void BfModule::HadSlotCountDependency()
BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance) BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance)
{ {
if (fieldInstance->mResolvedType->IsVar())
{
NOP;
}
if (mIsScratchModule) if (mIsScratchModule)
{ {
// Just fake it for the extern and unspecialized modules // Just fake it for the extern and unspecialized modules
@ -11875,11 +11876,6 @@ BfIRValue BfModule::AllocLocalVariable(BfType* type, const StringImpl& name, boo
void BfModule::DoAddLocalVariable(BfLocalVariable* localVar) void BfModule::DoAddLocalVariable(BfLocalVariable* localVar)
{ {
if (localVar->mResolvedType->IsVar())
{
BF_ASSERT((mCurMethodInstance->mIsUnspecialized) || (mCurMethodState->mClosureState != NULL) || (mHadVarUsage));
}
localVar->mLocalVarIdx = (int)mCurMethodState->mLocals.size(); localVar->mLocalVarIdx = (int)mCurMethodState->mLocals.size();
mCurMethodState->mLocals.push_back(localVar); mCurMethodState->mLocals.push_back(localVar);
@ -12045,9 +12041,7 @@ void BfModule::CreateDIRetVal()
}*/ }*/
if ((mCurMethodState->mRetVal) || (mCurMethodState->mRetValAddr)) if ((mCurMethodState->mRetVal) || (mCurMethodState->mRetValAddr))
{ {
BF_ASSERT((!mBfIRBuilder->mIgnoreWrites) || (mHadVarUsage));
BfType* dbgType = mCurMethodInstance->mReturnType; BfType* dbgType = mCurMethodInstance->mReturnType;
BfIRValue dbgValue = mCurMethodState->mRetVal.mValue; BfIRValue dbgValue = mCurMethodState->mRetVal.mValue;
if (mCurMethodInstance->HasStructRet()) if (mCurMethodInstance->HasStructRet())
@ -13195,8 +13189,7 @@ void BfModule::CreateStaticCtor()
if (!fieldInst->mFieldIncluded) if (!fieldInst->mFieldIncluded)
continue; continue;
if (fieldInst->mResolvedType->IsVar()) if (fieldInst->mResolvedType->IsVar())
{ {
BF_ASSERT(mHadVarUsage);
continue; continue;
} }
auto assignValue = GetFieldInitializerValue(fieldInst); auto assignValue = GetFieldInitializerValue(fieldInst);

View file

@ -1689,8 +1689,8 @@ bool BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
} }
} }
BfLogSysM("Setting revision. Type: %p Revision: %d\n", typeInstance, mRevision); //BfLogSysM("Setting revision. Type: %p Revision: %d\n", typeInstance, mRevision);
typeInstance->mRevision = mRevision; //typeInstance->mRevision = mRevision;
// Temporarily allow us to derive from private classes, to avoid infinite loop from TypeIsSubTypeOf // Temporarily allow us to derive from private classes, to avoid infinite loop from TypeIsSubTypeOf
SetAndRestoreValue<bool> prevSkipTypeProtectionChecks(typeInstance->mSkipTypeProtectionChecks, true); SetAndRestoreValue<bool> prevSkipTypeProtectionChecks(typeInstance->mSkipTypeProtectionChecks, true);
@ -2285,8 +2285,7 @@ bool BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
{ {
// Failed, just put in placeholder 'var' // Failed, just put in placeholder 'var'
AssertErrorState(); AssertErrorState();
resolvedFieldType = GetPrimitiveType(BfTypeCode_Var); resolvedFieldType = GetPrimitiveType(BfTypeCode_Var);
SetHadVarUsage();
} }
} }
@ -8693,9 +8692,6 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
// * <-> Var // * <-> Var
if ((typedVal.mType->IsVar()) || (toType->IsVar())) if ((typedVal.mType->IsVar()) || (toType->IsVar()))
{ {
BF_ASSERT(((mCurMethodInstance != NULL) && (mCurMethodInstance->mIsUnspecialized)) ||
((mCurMethodState != NULL) && (mCurMethodState->mClosureState != NULL)) ||
(mHadVarUsage));
return GetDefaultValue(toType); return GetDefaultValue(toType);
} }

View file

@ -1385,8 +1385,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD
} }
if (!initValue) if (!initValue)
{ {
initValue = GetDefaultTypedValue(GetPrimitiveType(BfTypeCode_Var)); initValue = GetDefaultTypedValue(GetPrimitiveType(BfTypeCode_Var));
SetHadVarUsage();
} }
if (initValue.mType->IsNull()) if (initValue.mType->IsNull())
{ {
@ -5455,8 +5454,7 @@ void BfModule::Visit(BfForEachStatement* forEachStmt)
} }
else if (isVarEnumerator) else if (isVarEnumerator)
{ {
// Generic method or mixin decl // Generic method or mixin decl
BF_ASSERT(mBfIRBuilder->mIgnoreWrites || mHadVarUsage);
} }
else if (!target.mType->IsTypeInstance()) else if (!target.mType->IsTypeInstance())
{ {