From 49dc1ab11ac8b7dc38385f828e8d9c927d83ab0a Mon Sep 17 00:00:00 2001 From: hadashiA Date: Fri, 24 May 2024 18:06:24 +0900 Subject: [PATCH] Fix directory structures --- Makefile | 2 - .../CodeWriter.cs | 90 -------- .../DiagnosticDescriptors.cs | 89 -------- .../Properties/launchSettings.json | 9 + .../ReferenceSymbols.cs | 27 --- .../SymbolExtensions.cs | 112 ---------- .../TypeMeta.cs | 115 ----------- .../VContainer.SourceGenerator.Roslyn3.csproj | 5 + .../Properties/launchSettings.json | 2 +- .../SampleSourceGenerator.cs | 56 ----- VContainer.sln | 17 +- .../VContainer/Runtime/Internal/FreeList.cs | 192 ++++++++++++++++++ .../Runtime/Internal/FreeList.cs.meta | 3 + .../VContainer/Runtime/Unity/LifetimeScope.cs | 2 +- VContainer/ProjectSettings/boot.config | 0 .../UserSettings/Layouts/default-2021.dwlt | 91 +++++---- .../VContainer.StandaloneTests.csproj | 11 +- 17 files changed, 276 insertions(+), 547 deletions(-) delete mode 100644 Makefile delete mode 100644 VContainer.SourceGenerator.Roslyn3/CodeWriter.cs delete mode 100644 VContainer.SourceGenerator.Roslyn3/DiagnosticDescriptors.cs create mode 100644 VContainer.SourceGenerator.Roslyn3/Properties/launchSettings.json delete mode 100644 VContainer.SourceGenerator.Roslyn3/ReferenceSymbols.cs delete mode 100644 VContainer.SourceGenerator.Roslyn3/SymbolExtensions.cs delete mode 100644 VContainer.SourceGenerator.Roslyn3/TypeMeta.cs delete mode 100644 VContainer.SourceGenerator/SampleSourceGenerator.cs create mode 100644 VContainer/Assets/VContainer/Runtime/Internal/FreeList.cs create mode 100644 VContainer/Assets/VContainer/Runtime/Internal/FreeList.cs.meta create mode 100644 VContainer/ProjectSettings/boot.config rename {VContainer.StandaloneTests => tests/VContainer.StandaloneTests}/VContainer.StandaloneTests.csproj (56%) diff --git a/Makefile b/Makefile deleted file mode 100644 index 58ddc461..00000000 --- a/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -bench: - /Applications/Unity/Hub/Editor/2021.2.4f1/Unity.app/Contents/MacOS/Unity -runTests -batchmode -projectPath ./VContainer.Benchmark -testResults ./TestResults.xml -testPlatform iOS -scriptingBackend IL2CPP diff --git a/VContainer.SourceGenerator.Roslyn3/CodeWriter.cs b/VContainer.SourceGenerator.Roslyn3/CodeWriter.cs deleted file mode 100644 index a4bd942e..00000000 --- a/VContainer.SourceGenerator.Roslyn3/CodeWriter.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Text; - -namespace VContainer.SourceGenerator -{ - public class CodeWriter - { - readonly struct IndentScope : IDisposable - { - readonly CodeWriter source; - - public IndentScope(CodeWriter source) - { - this.source = source; - source.IncreasaeIndent(); - } - - public void Dispose() - { - source.DecreaseIndent(); - } - } - - readonly struct BlockScope : IDisposable - { - readonly CodeWriter source; - - public BlockScope(CodeWriter source, string? startLine = null) - { - this.source = source; - source.AppendLine(startLine); - source.BeginBlock(); - } - - public void Dispose() - { - source.EndBlock(); - } - } - - readonly StringBuilder buffer = new(); - int indentLevel; - - public void AppendLine(string value = "") - { - if (string.IsNullOrEmpty(value)) - { - buffer.AppendLine(); - } - else - { - buffer.AppendLine($"{new string(' ', indentLevel * 4)} {value}"); - } - } - - public override string ToString() => buffer.ToString(); - - public IDisposable BeginIndentScope() => new IndentScope(this); - public IDisposable BeginBlockScope(string? startLine = null) => new BlockScope(this, startLine); - - public void IncreasaeIndent() - { - indentLevel++; - } - - public void DecreaseIndent() - { - if (indentLevel > 0) - indentLevel--; - } - - public void BeginBlock() - { - AppendLine("{"); - IncreasaeIndent(); - } - - public void EndBlock() - { - DecreaseIndent(); - AppendLine("}"); - } - - public void Clear() - { - buffer.Clear(); - indentLevel = 0; - } - } -} \ No newline at end of file diff --git a/VContainer.SourceGenerator.Roslyn3/DiagnosticDescriptors.cs b/VContainer.SourceGenerator.Roslyn3/DiagnosticDescriptors.cs deleted file mode 100644 index c5bbd8ac..00000000 --- a/VContainer.SourceGenerator.Roslyn3/DiagnosticDescriptors.cs +++ /dev/null @@ -1,89 +0,0 @@ -using Microsoft.CodeAnalysis; - -namespace VContainer.SourceGenerator -{ - static class DiagnosticDescriptors - { - const string Category = "VContainer.SourceGenerator.Roslyn3"; - - public static readonly DiagnosticDescriptor UnexpectedErrorDescriptor = new( - id: "VCON0001", - title: "Unexpected error during generation", - messageFormat: "Unexpected error occurred during code generation: {0}", - category: "Usage", - defaultSeverity: DiagnosticSeverity.Error, - isEnabledByDefault: true); - - public static readonly DiagnosticDescriptor AbstractNotAllow = new( - id: "VCON0002", - title: "Injectable type must not be abstract/interface", - messageFormat: "The injectable type of '{0}' is abstract/interface. It is not allowed", - category: Category, - defaultSeverity: DiagnosticSeverity.Error, - isEnabledByDefault: true); - - public static readonly DiagnosticDescriptor MultipleCtorAttributeNotSupported = new( - id: "VCON0003", - title: "[Inject] exists in multiple constructors", - messageFormat: "Multiple [Inject] constructors exists in '{0}'", - category: Category, - defaultSeverity: DiagnosticSeverity.Error, - isEnabledByDefault: true); - - public static readonly DiagnosticDescriptor MultipleInjectMethodNotSupported = new( - id: "VCON0004", - title: "[Inject] exists in multiple methods", - messageFormat: "Multiple [Inject] methods exists in '{0}'", - category: Category, - defaultSeverity: DiagnosticSeverity.Error, - isEnabledByDefault: true); - - public static readonly DiagnosticDescriptor NestedNotSupported = new( - id: "VCON0005", - title: "Nested type is not support to code generation.", - messageFormat: "The injectable object '{0}' is a nested type. It cannot support code generation ", - category: Category, - defaultSeverity: DiagnosticSeverity.Warning, - isEnabledByDefault: true); - - public static readonly DiagnosticDescriptor PrivateConstructorNotSupported = new( - id: "VCON0006", - title: "The private constructor is not supported to code generation.", - messageFormat: "The injectable constructor of '{0}' is private. It cannot support source generator.", - category: Category, - defaultSeverity: DiagnosticSeverity.Warning, - isEnabledByDefault: true); - - public static readonly DiagnosticDescriptor PrivateFieldNotSupported = new( - id: "VCON0007", - title: "The private [Inject] field is not supported to code generation.", - messageFormat: "The [Inject] field '{0}' does not have accessible to set from the same dll. It cannot support to inject by the source generator.", - category: Category, - defaultSeverity: DiagnosticSeverity.Warning, - isEnabledByDefault: true); - - public static readonly DiagnosticDescriptor PrivatePropertyNotSupported = new( - id: "VCON0008", - title: "The private [Inject] property is not supported to code generation", - messageFormat: "The [Inject] '{0}' does not have accessible to set from the same dll. It cannot support to inject by the source generator.", - category: Category, - defaultSeverity: DiagnosticSeverity.Warning, - isEnabledByDefault: true); - - public static readonly DiagnosticDescriptor PrivateMethodNotSupported = new( - id: "VCON0009", - title: "The private [Inject] method is not supported to code generation.", - messageFormat: "The [Inject] '{0}' does not have accessible to call from the same dll. It cannot support inject by the source generator.", - category: Category, - defaultSeverity: DiagnosticSeverity.Warning, - isEnabledByDefault: true); - - public static readonly DiagnosticDescriptor GenericsNotSupported = new( - id: "VCON0010", - title: "The [Inject] constructor or method that require generics argument is not supported to code generation.", - messageFormat: "[Inject] '{0}' needs generic arguments. It cannot inject by the source generator.", - category: Category, - defaultSeverity: DiagnosticSeverity.Warning, - isEnabledByDefault: true); - } -} diff --git a/VContainer.SourceGenerator.Roslyn3/Properties/launchSettings.json b/VContainer.SourceGenerator.Roslyn3/Properties/launchSettings.json new file mode 100644 index 00000000..c8afb642 --- /dev/null +++ b/VContainer.SourceGenerator.Roslyn3/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "DebugRoslynSourceGenerator": { + "commandName": "DebugRoslynComponent", + "targetProject": "../tests/VContainer.StandaloneTests/VContainer.StandaloneTests.csproj" + } + } +} \ No newline at end of file diff --git a/VContainer.SourceGenerator.Roslyn3/ReferenceSymbols.cs b/VContainer.SourceGenerator.Roslyn3/ReferenceSymbols.cs deleted file mode 100644 index e892dcf8..00000000 --- a/VContainer.SourceGenerator.Roslyn3/ReferenceSymbols.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Microsoft.CodeAnalysis; - -namespace VContainer.SourceGenerator -{ - public class ReferenceSymbols - { - public static ReferenceSymbols? Create(Compilation compilation) - { - var injectAttribute = compilation.GetTypeByMetadataName("VContainer.InjectAttribute"); - if (injectAttribute is null) - return null; - - return new ReferenceSymbols - { - VContainerInjectAttribute = injectAttribute, - VContainerInjectIgnoreAttribute = compilation.GetTypeByMetadataName("VContainer.InjectIgnoreAttribute")!, - AttributeBase = compilation.GetTypeByMetadataName("System.Attribute")!, - UnityEngineComponent = compilation.GetTypeByMetadataName("UnityEngine.Component"), - }; - } - - public INamedTypeSymbol VContainerInjectAttribute { get; private set; } = default!; - public INamedTypeSymbol VContainerInjectIgnoreAttribute { get; private set; } = default!; - public INamedTypeSymbol AttributeBase { get; private set; } = default!; - public INamedTypeSymbol? UnityEngineComponent { get; private set; } - } -} diff --git a/VContainer.SourceGenerator.Roslyn3/SymbolExtensions.cs b/VContainer.SourceGenerator.Roslyn3/SymbolExtensions.cs deleted file mode 100644 index 3a866872..00000000 --- a/VContainer.SourceGenerator.Roslyn3/SymbolExtensions.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.CodeAnalysis; - -namespace VContainer.SourceGenerator -{ - public static class SymbolExtensions - { - public static IEnumerable GetAllMembers(this INamedTypeSymbol symbol, bool withoutOverride = true) - { - // Iterate Parent -> Derived - if (symbol.BaseType != null) - { - foreach (var item in GetAllMembers(symbol.BaseType)) - { - // override item already iterated in parent type - if (!withoutOverride || !item.IsOverride) - { - yield return item; - } - } - } - - foreach (var item in symbol.GetMembers()) - { - if (!withoutOverride || !item.IsOverride) - { - yield return item; - } - } - } - - public static bool ContainsAttribute(this ISymbol symbol, INamedTypeSymbol attribtue) - { - return symbol.GetAttributes().Any(x => SymbolEqualityComparer.Default.Equals(x.AttributeClass, attribtue)); - } - - public static IEnumerable GetAllBaseTypes(this INamedTypeSymbol symbol) - { - var t = symbol.BaseType; - while (t != null) - { - yield return t; - t = t.BaseType; - } - } - - public static bool CanBeCallFromInternal(this ISymbol symbol) - { - return symbol.DeclaredAccessibility >= Accessibility.Internal; - } - - public static string GetClassDeclarationName(this INamedTypeSymbol symbol) - { - if (symbol.TypeArguments.Length == 0) - { - return symbol.Name; - } - - var sb = new StringBuilder(); - - sb.Append(symbol.Name); - sb.Append('<'); - - var first = true; - foreach (var typeArg in symbol.TypeArguments) - { - if (!first) - { - sb.Append(", "); - } - else - { - first = false; - } - sb.Append(typeArg.Name); - } - - sb.Append('>'); - - return sb.ToString(); - } - - public static IEnumerable DistinctBy(this IEnumerable source, Func keySelector) => DistinctBy(source, keySelector, null); - - public static IEnumerable DistinctBy(this IEnumerable source, Func keySelector, IEqualityComparer? comparer) - { - return DistinctByIterator(source, keySelector, comparer); - } - - static IEnumerable DistinctByIterator(IEnumerable source, Func keySelector, IEqualityComparer? comparer) - { - using IEnumerator enumerator = source.GetEnumerator(); - - if (enumerator.MoveNext()) - { - var set = new HashSet(comparer); - do - { - TSource element = enumerator.Current; - if (set.Add(keySelector(element))) - { - yield return element; - } - } - while (enumerator.MoveNext()); - } - } - } -} diff --git a/VContainer.SourceGenerator.Roslyn3/TypeMeta.cs b/VContainer.SourceGenerator.Roslyn3/TypeMeta.cs deleted file mode 100644 index d66dcbd4..00000000 --- a/VContainer.SourceGenerator.Roslyn3/TypeMeta.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -namespace VContainer.SourceGenerator -{ - class TypeMeta - { - public TypeDeclarationSyntax Syntax { get; } - public INamedTypeSymbol Symbol { get; } - public string TypeName { get; } - public string FullTypeName { get; } - public bool ExplicitInjectable { get; } - - public IReadOnlyList Constructors { get; } - public IReadOnlyList ExplictInjectConstructors { get; } - public IReadOnlyList InjectFields { get; } - public IReadOnlyList InjectProperties { get; } - public IReadOnlyList InjectMethods { get; } - - public bool IsGenerics => Symbol.Arity > 0; - - ReferenceSymbols references; - - public TypeMeta(TypeDeclarationSyntax syntax, INamedTypeSymbol symbol, ReferenceSymbols references) - { - Syntax = syntax; - Symbol = symbol; - this.references = references; - - TypeName = symbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat); - FullTypeName = symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); - - Constructors = GetConstructors(); - ExplictInjectConstructors = GetExplicitInjectConstructors(); - InjectFields = GetInjectFields(); - InjectProperties = GetInjectProperties(); - InjectMethods = GetInjectMethods(); - - ExplicitInjectable = ExplictInjectConstructors.Count > 0 || - InjectFields.Count > 0 || - InjectProperties.Count > 0 || - InjectMethods.Count > 0; - } - - public bool InheritsFrom(INamedTypeSymbol baseSymbol) - { - var baseName = baseSymbol.ToString(); - var symbol = Symbol; - while (true) - { - if (symbol.ToString() == baseName) - { - return true; - } - if (symbol.BaseType != null) - { - symbol = symbol.BaseType; - continue; - } - break; - } - return false; - } - - IReadOnlyList GetExplicitInjectConstructors() - { - return Constructors.Where(ctor => - { - return ctor.GetAttributes().Any(attr => - SymbolEqualityComparer.Default.Equals(attr.AttributeClass, references.VContainerInjectAttribute)); - }).ToArray(); - } - - IReadOnlyList GetConstructors() - { - return Symbol.InstanceConstructors - .Where(x => !x.IsImplicitlyDeclared) // remove empty ctor(struct always generate it), record's clone ctor - .ToArray(); - } - - IReadOnlyList GetInjectFields() - { - return Symbol.GetAllMembers() - .OfType() - .Where(x => x.ContainsAttribute(references.VContainerInjectAttribute)) - .DistinctBy(x => x.Name) - .ToArray(); - } - - IReadOnlyList GetInjectProperties() - { - return Symbol.GetAllMembers() - .OfType() - .Where(x => x.ContainsAttribute(references.VContainerInjectAttribute)) - .DistinctBy(x => x.Name) - .ToArray(); - } - - IReadOnlyList GetInjectMethods() - { - return Symbol.GetAllMembers() - .OfType() - .Where(x => x.MethodKind == MethodKind.Ordinary && - x.ContainsAttribute(references.VContainerInjectAttribute)) - .ToArray(); - } - - public bool IsNested() - { - return Syntax.Parent is TypeDeclarationSyntax; - } - } -} diff --git a/VContainer.SourceGenerator.Roslyn3/VContainer.SourceGenerator.Roslyn3.csproj b/VContainer.SourceGenerator.Roslyn3/VContainer.SourceGenerator.Roslyn3.csproj index 5d073c72..25031b9d 100644 --- a/VContainer.SourceGenerator.Roslyn3/VContainer.SourceGenerator.Roslyn3.csproj +++ b/VContainer.SourceGenerator.Roslyn3/VContainer.SourceGenerator.Roslyn3.csproj @@ -11,6 +11,11 @@ true + + + + diff --git a/VContainer.SourceGenerator/Properties/launchSettings.json b/VContainer.SourceGenerator/Properties/launchSettings.json index 835c79f4..c8afb642 100644 --- a/VContainer.SourceGenerator/Properties/launchSettings.json +++ b/VContainer.SourceGenerator/Properties/launchSettings.json @@ -3,7 +3,7 @@ "profiles": { "DebugRoslynSourceGenerator": { "commandName": "DebugRoslynComponent", - "targetProject": "../VContainer.SourceGenerator.Sample/VContainer.SourceGenerator.Sample.csproj" + "targetProject": "../tests/VContainer.StandaloneTests/VContainer.StandaloneTests.csproj" } } } \ No newline at end of file diff --git a/VContainer.SourceGenerator/SampleSourceGenerator.cs b/VContainer.SourceGenerator/SampleSourceGenerator.cs deleted file mode 100644 index b33d2132..00000000 --- a/VContainer.SourceGenerator/SampleSourceGenerator.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.IO; -using Microsoft.CodeAnalysis; - -namespace VContainer.SourceGenerator; - -/// -/// A sample source generator that creates C# classes based on the text file (in this case, Domain Driven Design ubiquitous language registry). -/// When using a simple text file as a baseline, we can create a non-incremental source generator. -/// -[Generator] -public class SampleSourceGenerator : ISourceGenerator -{ - public void Initialize(GeneratorInitializationContext context) - { - // No initialization required for this generator. - } - - public void Execute(GeneratorExecutionContext context) - { - // If you would like to put some data to non-compilable file (e.g. a .txt file), mark it as an Additional File. - - // Go through all files marked as an Additional File in file properties. - foreach (var additionalFile in context.AdditionalFiles) - { - if (additionalFile == null) - continue; - - // Check if the file name is the specific file that we expect. - if (Path.GetFileName(additionalFile.Path) != "DDD.UbiquitousLanguageRegistry.txt") - continue; - - var text = additionalFile.GetText(); - if (text == null) - continue; - - foreach (var line in text.Lines) - { - var className = line.ToString().Trim(); - - // Build up the source code. - string source = $@"// - -namespace Entities -{{ - public partial class {className} - {{ - }} -}} -"; - - // Add the source code to the compilation. - context.AddSource($"{className}.g.cs", source); - } - } - } -} \ No newline at end of file diff --git a/VContainer.sln b/VContainer.sln index d6fa4c0f..24ce89d4 100644 --- a/VContainer.sln +++ b/VContainer.sln @@ -1,23 +1,21 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VContainer.StandaloneTests", "VContainer.StandaloneTests\VContainer.StandaloneTests.csproj", "{1E5A1C0D-F315-4BDF-B0DA-6B0C3E7D8017}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VContainer.Standalone", "VContainer.Standalone\VContainer.Standalone.csproj", "{799DADAC-51EB-4039-8DAB-323DA3638F50}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VContainer.SourceGenerator.Roslyn3", "VContainer.SourceGenerator.Roslyn3\VContainer.SourceGenerator.Roslyn3.csproj", "{F80B5656-2CC8-425D-B140-DDCF2A1CA6CF}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VContainer.SourceGenerator", "VContainer.SourceGenerator\VContainer.SourceGenerator.csproj", "{FB341B09-8197-45B1-92AC-22D5385FC187}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{8519382C-D1E4-41D3-B5F0-931A273D78B2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VContainer.StandaloneTests", "tests\VContainer.StandaloneTests\VContainer.StandaloneTests.csproj", "{2B088390-5289-4E81-90ED-839C8F4242BE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1E5A1C0D-F315-4BDF-B0DA-6B0C3E7D8017}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1E5A1C0D-F315-4BDF-B0DA-6B0C3E7D8017}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1E5A1C0D-F315-4BDF-B0DA-6B0C3E7D8017}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1E5A1C0D-F315-4BDF-B0DA-6B0C3E7D8017}.Release|Any CPU.Build.0 = Release|Any CPU {799DADAC-51EB-4039-8DAB-323DA3638F50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {799DADAC-51EB-4039-8DAB-323DA3638F50}.Debug|Any CPU.Build.0 = Debug|Any CPU {799DADAC-51EB-4039-8DAB-323DA3638F50}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -30,5 +28,12 @@ Global {FB341B09-8197-45B1-92AC-22D5385FC187}.Debug|Any CPU.Build.0 = Debug|Any CPU {FB341B09-8197-45B1-92AC-22D5385FC187}.Release|Any CPU.ActiveCfg = Release|Any CPU {FB341B09-8197-45B1-92AC-22D5385FC187}.Release|Any CPU.Build.0 = Release|Any CPU + {2B088390-5289-4E81-90ED-839C8F4242BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B088390-5289-4E81-90ED-839C8F4242BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B088390-5289-4E81-90ED-839C8F4242BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B088390-5289-4E81-90ED-839C8F4242BE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {2B088390-5289-4E81-90ED-839C8F4242BE} = {8519382C-D1E4-41D3-B5F0-931A273D78B2} EndGlobalSection EndGlobal diff --git a/VContainer/Assets/VContainer/Runtime/Internal/FreeList.cs b/VContainer/Assets/VContainer/Runtime/Internal/FreeList.cs new file mode 100644 index 00000000..cef77354 --- /dev/null +++ b/VContainer/Assets/VContainer/Runtime/Internal/FreeList.cs @@ -0,0 +1,192 @@ +// using System; +// using System.Collections.Generic; +// using System.Runtime.InteropServices; +// +// namespace VContainer.Internal +// { +// public class FreeList where T : class +// { +// public int LastIndex => lastIndex; +// public bool IsDisposed => lastIndex == -2; +// +// readonly object gate = new(); +// T?[] values; +// int lastIndex = -1; +// +// public FreeList(int initialCapacity) +// { +// values = new T[initialCapacity]; +// } +// +// public ReadOnlySpan AsSpan() +// { +// if (lastIndex < 0) +// { +// return ReadOnlySpan.Empty; +// } +// return values.AsSpan(0, lastIndex + 1); +// } +// +// public T? this[int index] => values[index]; +// +// public void Add(T item) +// { +// lock (gate) +// { +// CheckDispose(); +// +// // try find blank +// var index = FindNullIndex(values); +// if (index == -1) +// { +// // full, 1, 4, 6,...resize(x1.5) +// var len = values.Length; +// var newValues = new T[len + len / 2]; +// Array.Copy(values, newValues, len); +// values = newValues; +// index = len; +// } +// +// values[index] = item; +// if (lastIndex < index) +// { +// lastIndex = index; +// } +// } +// } +// +// public void RemoveAt(int index) +// { +// lock (gate) +// { +// if (index < values.Length) +// { +// ref var v = ref values[index]; +// if (v == null) throw new KeyNotFoundException($"key index {index} is not found."); +// +// v = null; +// if (index == lastIndex) +// { +// lastIndex = FindLastNonNullIndex(values, index); +// } +// } +// } +// } +// +// public bool Remove(T value) +// { +// lock (gate) +// { +// if (lastIndex < 0) return false; +// +// var index = -1; +// var span = values.AsSpan(0, lastIndex + 1); +// for (var i = 0; i < span.Length; i++) +// { +// if (span[i] == value) +// { +// index = i; +// break; +// } +// } +// +// if (index != -1) +// { +// RemoveAt(index); +// return true; +// } +// } +// return false; +// } +// +// public void Clear() +// { +// lock (gate) +// { +// if (lastIndex > 0) +// { +// values.AsSpan(0, lastIndex + 1).Clear(); +// lastIndex = -1; +// } +// } +// } +// +// public void Dispose() +// { +// lock (gate) +// { +// lastIndex = -2; // -2 is disposed. +// } +// } +// +// void CheckDispose() +// { +// if (IsDisposed) +// { +// throw new ObjectDisposedException(GetType().FullName); +// } +// } +// +// #if NET6_0_OR_GREATER +// +// static int FindNullIndex(T?[] target) +// { +// var span = MemoryMarshal.CreateReadOnlySpan( +// ref UnsafeHelper.As(ref MemoryMarshal.GetArrayDataReference(target)), target.Length); +// return span.IndexOf(IntPtr.Zero); +// } +// +// #else +// +// static unsafe int FindNullIndex(T?[] target) +// { +// ref var head = ref UnsafeHelper.As(ref MemoryMarshal.GetReference(target.AsSpan())); +// fixed (void* p = &head) +// { +// var span = new ReadOnlySpan(p, target.Length); +// +// #if NETSTANDARD2_1 +// return span.IndexOf(IntPtr.Zero); +// #else +// for (int i = 0; i < span.Length; i++) +// { +// if (span[i] == IntPtr.Zero) return i; +// } +// return -1; +// #endif +// } +// } +// +// #endif +// +// #if NET8_0_OR_GREATER +// +// static int FindLastNonNullIndex(T?[] target, int lastIndex) +// { +// var span = MemoryMarshal.CreateReadOnlySpan( +// ref UnsafeHelper.As(ref MemoryMarshal.GetArrayDataReference(target)), lastIndex); // without lastIndexed value. +// var index = span.LastIndexOfAnyExcept(IntPtr.Zero); +// return index; // return -1 is ok(means empty) +// } +// +// #else +// +// static unsafe int FindLastNonNullIndex(T?[] target, int lastIndex) +// { +// ref var head = ref UnsafeHelper.As(ref MemoryMarshal.GetReference(target.AsSpan())); +// fixed (void* p = &head) +// { +// var span = new ReadOnlySpan(p, lastIndex); // without lastIndexed value. +// +// for (var i = span.Length - 1; i >= 0; i--) +// { +// if (span[i] != IntPtr.Zero) return i; +// } +// +// return -1; +// } +// } +// +// #endif +// } +// } diff --git a/VContainer/Assets/VContainer/Runtime/Internal/FreeList.cs.meta b/VContainer/Assets/VContainer/Runtime/Internal/FreeList.cs.meta new file mode 100644 index 00000000..7caa2a00 --- /dev/null +++ b/VContainer/Assets/VContainer/Runtime/Internal/FreeList.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ab65b7c977d342df8c7b3d914e896b30 +timeCreated: 1715093149 \ No newline at end of file diff --git a/VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs b/VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs index 03ef7160..b0e09ac8 100644 --- a/VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs +++ b/VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs @@ -217,7 +217,7 @@ public void Build() AwakeWaitingChildren(this); } - private void SetContainer(IObjectResolver container) + void SetContainer(IObjectResolver container) { Container = container; AutoInjectAll(); diff --git a/VContainer/ProjectSettings/boot.config b/VContainer/ProjectSettings/boot.config new file mode 100644 index 00000000..e69de29b diff --git a/VContainer/UserSettings/Layouts/default-2021.dwlt b/VContainer/UserSettings/Layouts/default-2021.dwlt index dde213f1..5867e2fe 100644 --- a/VContainer/UserSettings/Layouts/default-2021.dwlt +++ b/VContainer/UserSettings/Layouts/default-2021.dwlt @@ -19,7 +19,7 @@ MonoBehaviour: width: 1638 height: 1027 m_ShowMode: 4 - m_Title: Project + m_Title: Console m_RootView: {fileID: 6} m_MinSize: {x: 875, y: 300} m_MaxSize: {x: 10000, y: 10000} @@ -48,7 +48,7 @@ MonoBehaviour: m_MinSize: {x: 300, y: 200} m_MaxSize: {x: 24288, y: 16192} vertical: 0 - controlID: 26 + controlID: 37 --- !u!114 &3 MonoBehaviour: m_ObjectHideFlags: 52 @@ -68,8 +68,8 @@ MonoBehaviour: y: 0 width: 383.5 height: 977 - m_MinSize: {x: 276, y: 71} - m_MaxSize: {x: 4001, y: 4021} + m_MinSize: {x: 275, y: 50} + m_MaxSize: {x: 4000, y: 4000} m_ActualView: {fileID: 13} m_Panes: - {fileID: 13} @@ -92,10 +92,10 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 306 - height: 578.5 - m_MinSize: {x: 201, y: 221} - m_MaxSize: {x: 4001, y: 4021} + width: 305.5 + height: 579 + m_MinSize: {x: 200, y: 200} + m_MaxSize: {x: 4000, y: 4000} m_ActualView: {fileID: 14} m_Panes: - {fileID: 14} @@ -111,23 +111,23 @@ MonoBehaviour: m_Enabled: 1 m_EditorHideFlags: 1 m_Script: {fileID: 12006, guid: 0000000000000000e000000000000000, type: 0} - m_Name: ProjectBrowser + m_Name: ConsoleWindow m_EditorClassIdentifier: m_Children: [] m_Position: serializedVersion: 2 x: 0 - y: 578.5 + y: 579 width: 1254.5 - height: 398.5 - m_MinSize: {x: 231, y: 271} - m_MaxSize: {x: 10001, y: 10021} - m_ActualView: {fileID: 12} + height: 398 + m_MinSize: {x: 100, y: 100} + m_MaxSize: {x: 4000, y: 4000} + m_ActualView: {fileID: 17} m_Panes: - {fileID: 12} - {fileID: 17} - m_Selected: 0 - m_LastSelected: 1 + m_Selected: 1 + m_LastSelected: 0 --- !u!114 &6 MonoBehaviour: m_ObjectHideFlags: 52 @@ -223,7 +223,7 @@ MonoBehaviour: m_MinSize: {x: 200, y: 200} m_MaxSize: {x: 16192, y: 16192} vertical: 1 - controlID: 27 + controlID: 38 --- !u!114 &10 MonoBehaviour: m_ObjectHideFlags: 52 @@ -244,11 +244,11 @@ MonoBehaviour: x: 0 y: 0 width: 1254.5 - height: 578.5 + height: 579 m_MinSize: {x: 200, y: 100} m_MaxSize: {x: 16192, y: 8096} vertical: 0 - controlID: 28 + controlID: 39 --- !u!114 &11 MonoBehaviour: m_ObjectHideFlags: 52 @@ -264,12 +264,12 @@ MonoBehaviour: m_Children: [] m_Position: serializedVersion: 2 - x: 306 + x: 305.5 y: 0 - width: 948.5 - height: 578.5 - m_MinSize: {x: 202, y: 221} - m_MaxSize: {x: 4002, y: 4021} + width: 949 + height: 579 + m_MinSize: {x: 200, y: 200} + m_MaxSize: {x: 4000, y: 4000} m_ActualView: {fileID: 15} m_Panes: - {fileID: 15} @@ -292,7 +292,7 @@ MonoBehaviour: m_MaxSize: {x: 10000, y: 10000} m_TitleContent: m_Text: Project - m_Image: {fileID: -5467254957812901981, guid: 0000000000000000d000000000000000, + m_Image: {fileID: -5179483145760003458, guid: 0000000000000000d000000000000000, type: 0} m_Tooltip: m_Pos: @@ -305,13 +305,12 @@ MonoBehaviour: m_OverlayCanvas: m_LastAppliedPresetName: Default m_SaveData: [] + m_OverlaysVisible: 1 m_SearchFilter: m_NameFilter: m_ClassNames: [] m_AssetLabels: [] m_AssetBundleNames: [] - m_VersionControlStates: [] - m_SoftLockControlStates: [] m_ReferencingInstanceIDs: m_SceneHandles: m_ShowAllHits: 0 @@ -321,6 +320,7 @@ MonoBehaviour: - Assets/VContainer/Runtime m_Globs: [] m_OriginalText: + m_FilterByTypeIntersection: 0 m_ViewMode: 1 m_StartGridSize: 64 m_LastFolders: @@ -331,9 +331,9 @@ MonoBehaviour: m_IsLocked: 0 m_FolderTreeState: scrollPos: {x: 0, y: 0} - m_SelectedIDs: 76440000 - m_LastClickedID: 17526 - m_ExpandedIDs: 000000005e4400006644000000ca9a3bffffff7f + m_SelectedIDs: 84440000 + m_LastClickedID: 17540 + m_ExpandedIDs: 00000000724400007844000000ca9a3bffffff7f m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -361,7 +361,7 @@ MonoBehaviour: scrollPos: {x: 0, y: 0} m_SelectedIDs: m_LastClickedID: 0 - m_ExpandedIDs: 000000005e440000 + m_ExpandedIDs: 0000000072440000 m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -446,6 +446,7 @@ MonoBehaviour: m_OverlayCanvas: m_LastAppliedPresetName: Default m_SaveData: [] + m_OverlaysVisible: 1 m_ObjectsLockedBeforeSerialization: [] m_InstanceIDsLockedBeforeSerialization: m_PreviewResizer: @@ -475,25 +476,26 @@ MonoBehaviour: m_MaxSize: {x: 4000, y: 4000} m_TitleContent: m_Text: Hierarchy - m_Image: {fileID: 7966133145522015247, guid: 0000000000000000d000000000000000, + m_Image: {fileID: -3734745235275155857, guid: 0000000000000000d000000000000000, type: 0} m_Tooltip: m_Pos: serializedVersion: 2 x: 171 y: 83 - width: 305 - height: 557.5 + width: 304.5 + height: 558 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: m_LastAppliedPresetName: Default m_SaveData: [] + m_OverlaysVisible: 1 m_SceneHierarchy: m_TreeViewState: scrollPos: {x: 0, y: 0} m_SelectedIDs: m_LastClickedID: 0 - m_ExpandedIDs: 34fbffff + m_ExpandedIDs: 2cfbffff m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -533,15 +535,15 @@ MonoBehaviour: m_MaxSize: {x: 4000, y: 4000} m_TitleContent: m_Text: Scene - m_Image: {fileID: 2593428753322112591, guid: 0000000000000000d000000000000000, + m_Image: {fileID: 8634526014445323508, guid: 0000000000000000d000000000000000, type: 0} m_Tooltip: m_Pos: serializedVersion: 2 - x: 477 + x: 476.5 y: 83 - width: 946.5 - height: 557.5 + width: 947 + height: 558 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: m_LastAppliedPresetName: Default @@ -766,6 +768,7 @@ MonoBehaviour: id: Scene View/Tilemap Palette Helper index: 12 layout: 4 + m_OverlaysVisible: 1 m_WindowGUID: cc27987af1a868c49b0894db9c0f5429 m_Gizmos: 1 m_OverrideSceneCullingMask: 6917529027641081856 @@ -872,7 +875,7 @@ MonoBehaviour: m_MaxSize: {x: 4000, y: 4000} m_TitleContent: m_Text: Game - m_Image: {fileID: -6423792434712278376, guid: 0000000000000000d000000000000000, + m_Image: {fileID: 4621777727084837110, guid: 0000000000000000d000000000000000, type: 0} m_Tooltip: m_Pos: @@ -885,6 +888,7 @@ MonoBehaviour: m_OverlayCanvas: m_LastAppliedPresetName: Default m_SaveData: [] + m_OverlaysVisible: 1 m_SerializedViewNames: [] m_SerializedViewValues: [] m_PlayModeViewName: GameView @@ -965,16 +969,17 @@ MonoBehaviour: m_MaxSize: {x: 4000, y: 4000} m_TitleContent: m_Text: Console - m_Image: {fileID: -4327648978806127646, guid: 0000000000000000d000000000000000, + m_Image: {fileID: -4950941429401207979, guid: 0000000000000000d000000000000000, type: 0} m_Tooltip: m_Pos: serializedVersion: 2 x: 171 - y: 661.5 + y: 662 width: 1253.5 - height: 377.5 + height: 377 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: m_LastAppliedPresetName: Default m_SaveData: [] + m_OverlaysVisible: 1 diff --git a/VContainer.StandaloneTests/VContainer.StandaloneTests.csproj b/tests/VContainer.StandaloneTests/VContainer.StandaloneTests.csproj similarity index 56% rename from VContainer.StandaloneTests/VContainer.StandaloneTests.csproj rename to tests/VContainer.StandaloneTests/VContainer.StandaloneTests.csproj index fcd6d21b..fab7cd28 100644 --- a/VContainer.StandaloneTests/VContainer.StandaloneTests.csproj +++ b/tests/VContainer.StandaloneTests/VContainer.StandaloneTests.csproj @@ -1,13 +1,14 @@ - net7.0 + net8.0 false VCONTAINER_SOURCE_GENERATOR - + @@ -17,9 +18,9 @@ - - - + + + Analyzer false