public void UnionWith(CustomSet <T> other) { if (factory != other.factory) { throw new NotImplementedException(); } hashCode = 0; set.UnionWith(other.set); }
private MutabilityInspectionResult InspectClassOrStruct( ITypeSymbol type, HashSet <ITypeSymbol> typeStack ) { if (typeStack.Contains(type)) { // We have a cycle. If we're here, it means that either some read-only member causes the cycle (via IsMemberMutableRecursive), // or a generic parameter to a type causes the cycle (via IsTypeMutableRecursive). This is safe if the checks above have // passed and the remaining members are read-only immutable. So we can skip the current check, and allow the type to continue // to be evaluated. return(MutabilityInspectionResult.NotMutable()); } // We have a type that is not marked immutable, is not an interface, is not an immutable container, etc.. // If it is defined in a different assembly, we might not have the metadata to correctly analyze it; so we fail. if (TypeIsFromOtherAssembly(type)) { return(MutabilityInspectionResult.MutableType(type, MutabilityCause.IsAnExternalUnmarkedType)); } ImmutableHashSet <string> .Builder seenUnauditedReasonsBuilder = ImmutableHashSet.CreateBuilder <string>(); typeStack.Add(type); try { foreach (ISymbol member in type.GetExplicitNonStaticMembers()) { var result = InspectMemberRecursive(member, typeStack); if (result.IsMutable) { return(result); } seenUnauditedReasonsBuilder.UnionWith(result.SeenUnauditedReasons); } // We descend into the base class last if (type.BaseType != null) { var baseResult = InspectConcreteType(type.BaseType, typeStack); if (baseResult.IsMutable) { return(baseResult); } seenUnauditedReasonsBuilder.UnionWith(baseResult.SeenUnauditedReasons); } } finally { typeStack.Remove(type); } return(MutabilityInspectionResult.NotMutable(seenUnauditedReasonsBuilder.ToImmutable())); }
static void AddIfNotNull(ImmutableHashSet <IMethodSymbol> .Builder set, IEnumerable <IMethodSymbol>?others) { if (others != null) { set.UnionWith(others); } }
public ImmutableHashSet <string> GetAllTargetImageTags() { ImmutableHashSet <string> .Builder allTargetImageTags = ImmutableHashSet.CreateBuilder <string>(); allTargetImageTags.Add(targetImageConfiguration.GetImageTag()); allTargetImageTags.UnionWith(additionalTargetImageTags); return(allTargetImageTags.ToImmutable()); }
private static void UpdateMaterialization( Instruction instruction, ValueTag tagOrNull, FlowGraph graph, ImmutableHashSet <ValueTag> .Builder materialization) { var proto = instruction.Prototype; if (proto is LoadPrototype) { // Loads are fine; we can replace them without having to // materialize values. } else if (proto is GetFieldPointerPrototype) { // GFP instructions are harmless unless they escape. if (tagOrNull == null) { materialization.UnionWith( instruction.Arguments.Select( arg => UnfoldAliases(arg, graph))); } } else if (proto is StorePrototype) { // Stores are usually okay, unless they're used to make a // value escape. In that case, they're not okay. materialization.Add( UnfoldAliases( ((StorePrototype)proto).GetValue(instruction), graph)); } else { // All other instructions make values escape. materialization.UnionWith( instruction.Arguments.Select( arg => UnfoldAliases(arg, graph))); } }
private MutabilityInspectionResult InspectImmutableContainerType( ITypeSymbol type, HashSet <ITypeSymbol> typeStack ) { var namedType = type as INamedTypeSymbol; ImmutableHashSet <string> .Builder unauditedReasonsBuilder = ImmutableHashSet.CreateBuilder <string>(); for (int i = 0; i < namedType.TypeArguments.Length; i++) { var arg = namedType.TypeArguments[i]; var result = InspectType( arg, MutabilityInspectionFlags.Default, typeStack ); if (result.IsMutable) { if (result.Target == MutabilityTarget.Member) { // modify the result to prefix with container member. var prefix = ImmutableContainerTypes[type.GetFullTypeName()]; result = result.WithPrefixedMember(prefix[i]); } else { // modify the result to target the type argument if the // target is not a member result = result.WithTarget( MutabilityTarget.TypeArgument ); } return(result); } unauditedReasonsBuilder.UnionWith(result.SeenUnauditedReasons); } return(MutabilityInspectionResult.NotMutable(unauditedReasonsBuilder.ToImmutable())); }