* Remove parent parameter to CreateError and pParentType to GetErrorType
Only ever called with null; the one path that sets it to something else
only being hit if another ErrorType instance had it set to something
else, and so never happening.
* Remove TypeParent from ErrorType
Never not null
* Remove by-parent-type lookup for ErrorType instances.
Never used.
* Remove ErrAppendParentType
If called with an ErrorType calls ErrAppendParentCore which returns immediately if the namespace parent is either null or the rootNS, which is the only two possibilities.
As such it's always an no-op, so remove that call. Since this is the only call existing, remove entirely.
* Remove namespace parameter from LookupError and InsertError
Always the root namespace, so doesn't affect lookup.
* Make HasParent a simple boolean property.
Since the namespace, if set, is always the same one, and not examined beyond whether it is set, it's essentially a flag.
* Determine ErrorType.HasParent by whether nameText is null.
Always false if it's null, true otherwise, so use that as the storage.
* Add explanatory comment.
Commit migrated from https://github.com/dotnet/corefx/commit/
10a76752c95853ed74297fa817ff897ad389e3d8
ErrAppendParentCore(sym.parent, pctx);
}
- private void ErrAppendParentType(CType pType, SubstContext pctx)
- {
- if (pType is ErrorType err)
- {
- if (err.HasTypeParent())
- {
- ErrAppendType(err.GetTypeParent(), null);
- ErrAppendChar('.');
- }
- else
- {
- ErrAppendParentCore(err.GetNSParent(), pctx);
- }
- }
- else if (pType is AggregateType agg)
- {
- ErrAppendParentCore(agg.GetOwningAggregate(), pctx);
- }
- else
- {
- var part = pType.GetBaseOrParameterOrElementType();
- if (part != null)
- {
- ErrAppendType(part, null);
- ErrAppendChar('.');
- }
- }
- }
-
private void ErrAppendParentCore(Symbol parent, SubstContext pctx)
{
if (null == parent)
case TypeKind.TK_ErrorType:
ErrorType err = (ErrorType)pType;
- if (err.HasParent())
+ if (err.HasParent)
{
Debug.Assert(err.nameText != null && err.typeArgs != null);
- ErrAppendParentType(pType, pctx);
ErrAppendName(err.nameText);
ErrAppendTypeParameters(err.typeArgs, pctx, true);
}
switch (_typeDest.GetTypeKind())
{
case TypeKind.TK_ErrorType:
- Debug.Assert(((ErrorType)_typeDest).HasParent());
+ Debug.Assert(((ErrorType)_typeDest).HasParent);
if (_typeSrc != _typeDest)
{
return false;
}
_pFixedResults[iParam] = GetTypeManager().GetErrorType(
- null/*pParentType*/,
- null,
((TypeParameterType)_pMethodTypeParameters[iParam]).GetName(),
BSYMMGR.EmptyTypeArray());
}
public Name nameText;
public TypeArray typeArgs;
- public bool HasParent() { return _pParentType != null || _pParentNS != null; }
-
- public bool HasTypeParent() { return _pParentType != null; }
- public CType GetTypeParent() { return _pParentType; }
- public void SetTypeParent(CType pType) { _pParentType = pType; }
-
- public bool HasNSParent() { return _pParentNS != null; }
- public AssemblyQualifiedNamespaceSymbol GetNSParent() { return _pParentNS; }
- public void SetNSParent(AssemblyQualifiedNamespaceSymbol pNS) { _pParentNS = pNS; }
-
- private CType _pParentType;
- private AssemblyQualifiedNamespaceSymbol _pParentNS;
+ // ErrorTypes are always either the per-TypeManager singleton ErrorType
+ // that has a null nameText and no namespace parent, or else have a
+ // non-null nameText and have the root namespace as the namespace parent,
+ // so checking that nameText isn't null is equivalent to checking if the
+ // type has a parent.
+ public bool HasParent => nameText != null;
}
}
public void InitFromParent()
{
Debug.Assert(!(this is AggregateType));
- _fHasErrors = (this is ErrorType err ? err.GetTypeParent() : GetBaseOrParameterOrElementType()).HasErrors();
+ Debug.Assert(!(this is ErrorType));
+ _fHasErrors = GetBaseOrParameterOrElementType().HasErrors();
}
public bool HasErrors()
// be equivalent or convertible (like ANONMETHSYMs)
public bool IsNeverSameType()
{
- return this is MethodGroupType || this is ErrorType err && !err.HasParent();
+ return this is MethodGroupType || this is ErrorType err && !err.HasParent;
}
}
}
public ErrorType CreateError(
Name name,
- CType parent,
- AssemblyQualifiedNamespaceSymbol pParentNS,
Name nameText,
TypeArray typeArgs)
{
e.SetName(name);
e.nameText = nameText;
e.typeArgs = typeArgs;
- e.SetTypeParent(parent);
- e.SetNSParent(pParentNS);
e.SetTypeKind(TypeKind.TK_ErrorType);
return e;
_typeTable = new TypeTable();
// special types with their own symbol kind.
- _errorType = _typeFactory.CreateError(null, null, null, null, null);
+ _errorType = _typeFactory.CreateError(null, null, null);
_voidType = _typeFactory.CreateVoid();
_nullType = _typeFactory.CreateNull();
_typeMethGrp = _typeFactory.CreateMethodGroup();
}
public ErrorType GetErrorType(
- CType pParentType,
- AssemblyQualifiedNamespaceSymbol pParentNS,
Name nameText,
TypeArray typeArgs)
{
Debug.Assert(nameText != null);
- Debug.Assert(pParentType == null || pParentNS == null);
- if (pParentType == null && pParentNS == null)
- {
- // Use the root namespace as the parent.
- pParentNS = _BSymmgr.GetRootNsAid();
- }
if (typeArgs == null)
{
typeArgs = BSYMMGR.EmptyTypeArray();
Name name = _BSymmgr.GetNameFromPtrs(nameText, typeArgs);
Debug.Assert(name != null);
- ErrorType pError = null;
- if (pParentType != null)
- {
- pError = _typeTable.LookupError(name, pParentType);
- }
- else
- {
- Debug.Assert(pParentNS != null);
- pError = _typeTable.LookupError(name, pParentNS);
- }
+ ErrorType pError = _typeTable.LookupError(name);
if (pError == null)
{
// No existing error symbol. Create a new one.
- pError = _typeFactory.CreateError(name, pParentType, pParentNS, nameText, typeArgs);
+ pError = _typeFactory.CreateError(name, nameText, typeArgs);
pError.SetErrors(true);
- if (pParentType != null)
- {
- _typeTable.InsertError(name, pParentType, pError);
- }
- else
- {
- _typeTable.InsertError(name, pParentNS, pError);
- }
+ _typeTable.InsertError(name, pError);
}
else
{
case TypeKind.TK_ErrorType:
ErrorType err = (ErrorType)type;
- if (err.HasParent())
+ if (err.HasParent)
{
Debug.Assert(err.nameText != null && err.typeArgs != null);
-
- CType pParentType = null;
- if (err.HasTypeParent())
- {
- pParentType = SubstTypeCore(err.GetTypeParent(), pctx);
- }
-
TypeArray typeArgs = SubstTypeArray(err.typeArgs, pctx);
- if (typeArgs != err.typeArgs || (err.HasTypeParent() && pParentType != err.GetTypeParent()))
+ if (typeArgs != err.typeArgs)
{
- return GetErrorType(pParentType, err.GetNSParent(), err.nameText, typeArgs);
+ return GetErrorType(err.nameText, typeArgs);
}
}
+
return type;
case TypeKind.TK_TypeParameterType:
case TypeKind.TK_ErrorType:
ErrorType errSrc = (ErrorType)typeSrc;
- if (!(typeDst is ErrorType errDst) || !errSrc.HasParent() || !errDst.HasParent())
+ if (!(typeDst is ErrorType errDst) || !errSrc.HasParent || !errDst.HasParent)
return false;
- {
- Debug.Assert(errSrc.nameText != null && errSrc.typeArgs != null);
- Debug.Assert(errDst.nameText != null && errDst.typeArgs != null);
- if (errSrc.nameText != errDst.nameText || errSrc.typeArgs.Count != errDst.typeArgs.Count)
- return false;
+ {
+ Debug.Assert(errSrc.nameText != null && errSrc.typeArgs != null);
+ Debug.Assert(errDst.nameText != null && errDst.typeArgs != null);
- if (errSrc.HasTypeParent() != errDst.HasTypeParent())
- {
- return false;
- }
- if (errSrc.HasTypeParent())
- {
- if (errSrc.GetTypeParent() != errDst.GetTypeParent())
- {
- return false;
- }
- if (!SubstEqualTypesCore(errDst.GetTypeParent(), errSrc.GetTypeParent(), pctx))
- {
- return false;
- }
- }
- else
- {
- if (errSrc.GetNSParent() != errDst.GetNSParent())
- {
- return false;
- }
- }
+ if (errSrc.nameText != errDst.nameText || errSrc.typeArgs.Count != errDst.typeArgs.Count
+ || errSrc.HasParent != errDst.HasParent)
+ {
+ return false;
+ }
- // All the args must unify.
- for (int i = 0; i < errSrc.typeArgs.Count; i++)
- {
- if (!SubstEqualTypesCore(errDst.typeArgs[i], errSrc.typeArgs[i], pctx))
- return false;
- }
+ // All the args must unify.
+ for (int i = 0; i < errSrc.typeArgs.Count; i++)
+ {
+ if (!SubstEqualTypesCore(errDst.typeArgs[i], errSrc.typeArgs[i], pctx))
+ return false;
}
+ }
+
return true;
case TypeKind.TK_TypeParameterType:
case TypeKind.TK_ErrorType:
ErrorType err = (ErrorType)type;
- if (err.HasParent())
+ if (err.HasParent)
{
Debug.Assert(err.nameText != null && err.typeArgs != null);
if (TypeContainsType(err.typeArgs[i], typeFind))
return true;
}
- if (err.HasTypeParent())
- {
- type = err.GetTypeParent();
- goto LRecurse;
- }
}
+
return false;
case TypeKind.TK_TypeParameterType:
case TypeKind.TK_ErrorType:
ErrorType err = (ErrorType)type;
- if (err.HasParent())
+ if (err.HasParent)
{
Debug.Assert(err.nameText != null && err.typeArgs != null);
return true;
}
}
- if (err.HasTypeParent())
- {
- type = err.GetTypeParent();
- goto LRecurse;
- }
}
+
return false;
case TypeKind.TK_TypeParameterType:
{
// Two way hashes
private readonly Dictionary<KeyPair<AggregateSymbol, Name>, AggregateType> _pAggregateTable;
- private readonly Dictionary<KeyPair<CType, Name>, ErrorType> _pErrorWithTypeParentTable;
- private readonly Dictionary<KeyPair<AssemblyQualifiedNamespaceSymbol, Name>, ErrorType> _pErrorWithNamespaceParentTable;
private readonly Dictionary<KeyPair<CType, Name>, ArrayType> _pArrayTable;
private readonly Dictionary<KeyPair<CType, Name>, ParameterModifierType> _pParameterModifierTable;
// One way hashes
+ private readonly Dictionary<Name, ErrorType> _pErrorWithNamespaceParentTable;
private readonly Dictionary<CType, PointerType> _pPointerTable;
private readonly Dictionary<CType, NullableType> _pNullableTable;
private readonly Dictionary<TypeParameterSymbol, TypeParameterType> _pTypeParameterTable;
public TypeTable()
{
_pAggregateTable = new Dictionary<KeyPair<AggregateSymbol, Name>, AggregateType>();
- _pErrorWithNamespaceParentTable = new Dictionary<KeyPair<AssemblyQualifiedNamespaceSymbol, Name>, ErrorType>();
- _pErrorWithTypeParentTable = new Dictionary<KeyPair<CType, Name>, ErrorType>();
+ _pErrorWithNamespaceParentTable = new Dictionary<Name, ErrorType>();
_pArrayTable = new Dictionary<KeyPair<CType, Name>, ArrayType>();
_pParameterModifierTable = new Dictionary<KeyPair<CType, Name>, ParameterModifierType>();
_pPointerTable = new Dictionary<CType, PointerType>();
_pAggregateTable.Add(new KeyPair<AggregateSymbol, Name>(pAggregateSymbol, pName), pAggregate);
}
- public ErrorType LookupError(Name pName, CType pParentType)
- {
- var key = new KeyPair<CType, Name>(pParentType, pName);
- ErrorType result;
- if (_pErrorWithTypeParentTable.TryGetValue(key, out result))
- {
- return result;
- }
- return null;
- }
-
- public ErrorType LookupError(Name pName, AssemblyQualifiedNamespaceSymbol pParentNS)
- {
- var key = new KeyPair<AssemblyQualifiedNamespaceSymbol, Name>(pParentNS, pName);
- ErrorType result;
- if (_pErrorWithNamespaceParentTable.TryGetValue(key, out result))
- {
- return result;
- }
- return null;
- }
-
- public void InsertError(Name pName, CType pParentType, ErrorType pError)
- {
- Debug.Assert(LookupError(pName, pParentType) == null);
- _pErrorWithTypeParentTable.Add(new KeyPair<CType, Name>(pParentType, pName), pError);
- }
+ public ErrorType LookupError(Name pName) =>
+ _pErrorWithNamespaceParentTable.TryGetValue(pName, out ErrorType result) ? result : null;
- public void InsertError(Name pName, AssemblyQualifiedNamespaceSymbol pParentNS, ErrorType pError)
+ public void InsertError(Name pName, ErrorType pError)
{
- Debug.Assert(LookupError(pName, pParentNS) == null);
- _pErrorWithNamespaceParentTable.Add(new KeyPair<AssemblyQualifiedNamespaceSymbol, Name>(pParentNS, pName), pError);
+ Debug.Assert(LookupError(pName) == null);
+ _pErrorWithNamespaceParentTable.Add(pName, pError);
}
public ArrayType LookupArray(Name pName, CType pElementType)