Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dev/rolf/bgen-accumul…
Browse files Browse the repository at this point in the history
…ate-errors
  • Loading branch information
rolfbjarne committed Jan 15, 2025
2 parents 8a4de0e + 3eb9920 commit 41e2f0f
Show file tree
Hide file tree
Showing 73 changed files with 1,058 additions and 693 deletions.
47 changes: 29 additions & 18 deletions src/Metal/MTLEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -971,14 +971,39 @@ public enum MTLPipelineOption : ulong {
/// <summary>Enumerates the hardware feature sets that are available on a device.</summary>
[Native]
public enum MTLFeatureSet : ulong {
#if XAMCORE_5_0
[NoMacCatalyst]
#elif __MACCATALYST__
[Obsolete ("Not available on the current platform.")]
#endif
[NoTV, NoMac]
iOS_GPUFamily1_v1 = 0,
#if XAMCORE_5_0
[NoMacCatalyst]
#elif __MACCATALYST__
[Obsolete ("Not available on the current platform.")]
#endif
[NoTV, NoMac]
iOS_GPUFamily1_v2 = 2,
#if XAMCORE_5_0
[NoMacCatalyst]
#elif __MACCATALYST__
[Obsolete ("Not available on the current platform.")]
#endif
[NoTV, NoMac]
iOS_GPUFamily2_v1 = 1,
#if XAMCORE_5_0
[NoMacCatalyst]
#elif __MACCATALYST__
[Obsolete ("Not available on the current platform.")]
#endif
[NoTV, NoMac]
iOS_GPUFamily2_v2 = 3,
#if XAMCORE_5_0
[NoMacCatalyst]
#elif __MACCATALYST__
[Obsolete ("Not available on the current platform.")]
#endif
[NoTV, NoMac]
iOS_GPUFamily3_v1 = 4,
[NoTV, NoMac, NoMacCatalyst]
Expand Down Expand Up @@ -1010,29 +1035,14 @@ public enum MTLFeatureSet : ulong {
[NoiOS, NoTV, NoMacCatalyst]
macOS_GPUFamily1_v1 = 10000,

#if !NET
[Obsolete ("Use 'macOS_GPUFamily1_v1' instead.")]
OSX_GPUFamily1_v1 = macOS_GPUFamily1_v1,
#endif

[NoiOS, NoTV]
[NoMacCatalyst]
macOS_GPUFamily1_v2 = 10001,

#if !NET
[Obsolete ("Use 'macOS_GPUFamily1_v2' instead.")]
OSX_GPUFamily1_v2 = macOS_GPUFamily1_v2,
#endif

[NoiOS, NoTV]
[NoMacCatalyst]
macOS_ReadWriteTextureTier2 = 10002,

#if !NET
[Obsolete ("Use 'macOS_ReadWriteTextureTier2' instead.")]
OSX_ReadWriteTextureTier2 = macOS_ReadWriteTextureTier2,
#endif

[NoiOS, NoTV]
[NoMacCatalyst]
macOS_GPUFamily1_v3 = 10003,
Expand All @@ -1045,9 +1055,10 @@ public enum MTLFeatureSet : ulong {
[NoMacCatalyst]
macOS_GPUFamily2_v1 = 10005,

#if !NET
[Obsolete ("Use 'tvOS_GPUFamily1_v1' instead.")]
TVOS_GPUFamily1_v1 = 30000,
#if XAMCORE_5_0
[NoMacCatalyst]
#elif __MACCATALYST__
[Obsolete ("Not available on the current platform.")]
#endif

[NoiOS, NoMac]
Expand Down
3 changes: 3 additions & 0 deletions src/bgen/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,7 @@ void GenerateStrongDictionaryTypes ()

print ("namespace {0} {{", dictType.Namespace);
indent++;
WriteDocumentation (dictType);
PrintPlatformAttributes (dictType);
PrintExperimentalAttribute (dictType);
print ("public partial class {0} : DictionaryContainer {{", typeName);
Expand All @@ -1844,6 +1845,7 @@ void GenerateStrongDictionaryTypes ()
keyname = keyContainerType + "." + keyname + "!";
}

WriteDocumentation (pi);
PrintPlatformAttributes (pi);
string modifier = pi.IsInternal (this) ? "internal" : "public";

Expand Down Expand Up @@ -6265,6 +6267,7 @@ public void Generate (Type type)
print ("static {0}? _{1};", fieldTypeName, field_pi.Name);
}

WriteDocumentation (field_pi);
PrintAttributes (field_pi, preserve: true, advice: true);
PrintObsoleteAttributes (field_pi);
print ("[Field (\"{0}\", \"{1}\")]", fieldAttr.SymbolName, library_path ?? library_name);
Expand Down
220 changes: 220 additions & 0 deletions src/mlcompute.cs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/oslog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ enum OSLogMessageComponentArgumentCategory : long {
[TV (15, 0), iOS (15, 0), MacCatalyst (15, 0)]
[Native]
enum OSLogStoreScope : long {
#if XAMCORE_5_0
[NoTV, NoiOS, NoMacCatalyst]
#endif
#if !MONOMAC
[Obsolete ("Not available on the current platform.")]
#endif
System = 0,
CurrentProcessIdentifier = 1,
}
Expand Down
7 changes: 2 additions & 5 deletions src/replaykit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,8 @@ interface RPBroadcastHandler : NSExtensionRequestHandling {
[Export ("updateServiceInfo:")]
void UpdateServiceInfo (NSDictionary<NSString, INSCoding> serviceInfo);

// NSInvalidArgumentException -[RPBroadcastHandler updateBroadcastURL:]: unrecognized selector sent to instance 0x608001a4b160
// https://trello.com/c/eA440suj/91-33875315-rpbroadcasthandler-updatebroadcasturl-unrecognized-selector
//
//[Export ("updateBroadcastURL:")]
//void UpdateBroadcastUrl (NSUrl broadcastUrl);
[Export ("updateBroadcastURL:")]
void UpdateBroadcastUrl (NSUrl broadcastUrl);
}

/// <related type="externalDocumentation" href="https://developer.apple.com/reference/ReplayKit/RPBroadcastMP4ClipHandler">Apple documentation for <c>RPBroadcastMP4ClipHandler</c></related>
Expand Down
32 changes: 22 additions & 10 deletions src/rgen/Microsoft.Macios.Generator/DataModel/CodeChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,20 @@ public ImmutableArray<Method> Methods {

// return those libs needed by smart enums
foreach (var enumMember in EnumMembers) {
if (visited.Add (enumMember.LibraryName)) // if already visited we cannot add it
yield return (enumMember.LibraryName, enumMember.LibraryPath);
if (enumMember.FieldInfo is null)
continue;
var (_, libraryName, libraryPath) = enumMember.FieldInfo.Value;
if (visited.Add (libraryName)) // if already visited, we cannot add it
yield return (libraryName, libraryPath);
}

// return those libs needed by field properties
foreach (var property in Properties) {
if (property.ExportFieldData is null)
continue;
var (_, libraryName, libraryPath) = property.ExportFieldData.Value;
if (visited.Add (libraryName)) // if already visited, we cannot add it
yield return (libraryName, libraryPath);
}
}
}
Expand Down Expand Up @@ -244,22 +256,22 @@ internal static bool Skip (MethodDeclarationSyntax methodDeclarationSyntax, Sema

delegate bool SkipDelegate<in T> (T declarationSyntax, SemanticModel semanticModel);

delegate bool TryCreateDelegate<in T, TR> (T declaration, SemanticModel semanticModel,
delegate bool TryCreateDelegate<in T, TR> (T declaration, RootBindingContext context,
[NotNullWhen (true)] out TR? change)
where T : MemberDeclarationSyntax
where TR : struct;

static void GetMembers<T, TR> (TypeDeclarationSyntax baseDeclarationSyntax, SemanticModel semanticModel,
static void GetMembers<T, TR> (TypeDeclarationSyntax baseDeclarationSyntax, RootBindingContext context,
SkipDelegate<T> skip, TryCreateDelegate<T, TR> tryCreate, out ImmutableArray<TR> members)
where T : MemberDeclarationSyntax
where TR : struct
{
var bucket = ImmutableArray.CreateBuilder<TR> ();
var declarations = baseDeclarationSyntax.Members.OfType<T> ();
foreach (var declaration in declarations) {
if (skip (declaration, semanticModel))
if (skip (declaration, context.SemanticModel))
continue;
if (tryCreate (declaration, semanticModel, out var change))
if (tryCreate (declaration, context, out var change))
bucket.Add (change.Value);
}

Expand Down Expand Up @@ -357,12 +369,12 @@ internal CodeChanges (BindingInfo bindingInfo, string name, ImmutableArray<strin

// use the generic method to get the members, we are using an out param to try an minimize the number of times
// the value types are copied
GetMembers<ConstructorDeclarationSyntax, Constructor> (classDeclaration, context.SemanticModel, Skip,
GetMembers<ConstructorDeclarationSyntax, Constructor> (classDeclaration, context, Skip,
Constructor.TryCreate, out constructors);
GetMembers<PropertyDeclarationSyntax, Property> (classDeclaration, context.SemanticModel, Skip, Property.TryCreate,
GetMembers<PropertyDeclarationSyntax, Property> (classDeclaration, context, Skip, Property.TryCreate,
out properties);
GetMembers<EventDeclarationSyntax, Event> (classDeclaration, context.SemanticModel, Skip, Event.TryCreate, out events);
GetMembers<MethodDeclarationSyntax, Method> (classDeclaration, context.SemanticModel, Skip, Method.TryCreate,
GetMembers<EventDeclarationSyntax, Event> (classDeclaration, context, Skip, Event.TryCreate, out events);
GetMembers<MethodDeclarationSyntax, Method> (classDeclaration, context, Skip, Method.TryCreate,
out methods);
}

Expand Down
9 changes: 5 additions & 4 deletions src/rgen/Microsoft.Macios.Generator/DataModel/Constructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Macios.Generator.Availability;
using Microsoft.Macios.Generator.Context;
using Microsoft.Macios.Generator.Extensions;

namespace Microsoft.Macios.Generator.DataModel;
Expand Down Expand Up @@ -51,20 +52,20 @@ public Constructor (string type,
Parameters = parameters;
}

public static bool TryCreate (ConstructorDeclarationSyntax declaration, SemanticModel semanticModel,
public static bool TryCreate (ConstructorDeclarationSyntax declaration, RootBindingContext context,
[NotNullWhen (true)] out Constructor? change)
{
if (semanticModel.GetDeclaredSymbol (declaration) is not IMethodSymbol constructor) {
if (context.SemanticModel.GetDeclaredSymbol (declaration) is not IMethodSymbol constructor) {
change = null;
return false;
}

var attributes = declaration.GetAttributeCodeChanges (semanticModel);
var attributes = declaration.GetAttributeCodeChanges (context.SemanticModel);
var parametersBucket = ImmutableArray.CreateBuilder<Parameter> ();
// loop over the parameters of the construct since changes on those implies a change in the generated code
foreach (var parameter in constructor.Parameters) {
var parameterDeclaration = declaration.ParameterList.Parameters [parameter.Ordinal];
if (!Parameter.TryCreate (parameter, parameterDeclaration, semanticModel, out var parameterChange))
if (!Parameter.TryCreate (parameter, parameterDeclaration, context.SemanticModel, out var parameterChange))
continue;
parametersBucket.Add (parameterChange.Value);
}
Expand Down
20 changes: 4 additions & 16 deletions src/rgen/Microsoft.Macios.Generator/DataModel/EnumMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ namespace Microsoft.Macios.Generator.DataModel;
/// </summary>
public string Name { get; }

/// <summary>
/// Name of the library that contains the smart enum definition.
/// </summary>
public string LibraryName { get; }

/// <summary>
/// Path of the library that contains the smart enum definition.
/// </summary>
public string? LibraryPath { get; }

/// <summary>
/// The platform availability of the enum value.
/// </summary>
Expand All @@ -37,7 +27,7 @@ namespace Microsoft.Macios.Generator.DataModel;
/// <summary>
/// The data of the field attribute used to mark the value as a binding.
/// </summary>
public FieldData<EnumValue>? FieldData { get; }
public FieldInfo<EnumValue>? FieldInfo { get; }

/// <summary>
/// Get the attributes added to the member.
Expand All @@ -61,9 +51,7 @@ public EnumMember (string name,
ImmutableArray<AttributeCodeChange> attributes)
{
Name = name;
LibraryName = libraryName;
LibraryPath = libraryPath;
FieldData = fieldData;
FieldInfo = fieldData is null ? null : new (fieldData.Value, libraryName, libraryPath);
SymbolAvailability = symbolAvailability;
Attributes = attributes;
}
Expand Down Expand Up @@ -92,7 +80,7 @@ public bool Equals (EnumMember other)
return false;
if (SymbolAvailability != other.SymbolAvailability)
return false;
if (FieldData != other.FieldData)
if (FieldInfo != other.FieldInfo)
return false;

var attrComparer = new AttributesEqualityComparer ();
Expand Down Expand Up @@ -125,7 +113,7 @@ public override int GetHashCode ()
public override string ToString ()
{
var sb = new StringBuilder (
$"{{ Name: '{Name}' SymbolAvailability: {SymbolAvailability} FieldData: {FieldData} Attributes: [");
$"{{ Name: '{Name}' SymbolAvailability: {SymbolAvailability} FieldInfo: {FieldInfo} Attributes: [");
sb.AppendJoin (", ", Attributes);
sb.Append ("] }");
return sb.ToString ();
Expand Down
11 changes: 6 additions & 5 deletions src/rgen/Microsoft.Macios.Generator/DataModel/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Macios.Generator.Availability;
using Microsoft.Macios.Generator.Context;
using Microsoft.Macios.Generator.Extensions;

namespace Microsoft.Macios.Generator.DataModel;
Expand Down Expand Up @@ -100,27 +101,27 @@ public override int GetHashCode ()
return !left.Equals (right);
}

public static bool TryCreate (EventDeclarationSyntax declaration, SemanticModel semanticModel,
public static bool TryCreate (EventDeclarationSyntax declaration, RootBindingContext context,
[NotNullWhen (true)] out Event? change)
{
var memberName = declaration.Identifier.ToFullString ().Trim ();
// get the symbol from the property declaration
if (semanticModel.GetDeclaredSymbol (declaration) is not IEventSymbol eventSymbol) {
if (context.SemanticModel.GetDeclaredSymbol (declaration) is not IEventSymbol eventSymbol) {
change = null;
return false;
}

var type = eventSymbol.Type.ToDisplayString ().Trim ();
var attributes = declaration.GetAttributeCodeChanges (semanticModel);
var attributes = declaration.GetAttributeCodeChanges (context.SemanticModel);
ImmutableArray<Accessor> accessorCodeChanges = [];
if (declaration.AccessorList is not null && declaration.AccessorList.Accessors.Count > 0) {
// calculate any possible changes in the accessors of the property
var accessorsBucket = ImmutableArray.CreateBuilder<Accessor> ();
foreach (var accessorDeclaration in declaration.AccessorList.Accessors) {
if (semanticModel.GetDeclaredSymbol (accessorDeclaration) is not ISymbol accessorSymbol)
if (context.SemanticModel.GetDeclaredSymbol (accessorDeclaration) is not ISymbol accessorSymbol)
continue;
var kind = accessorDeclaration.Kind ().ToAccessorKind ();
var accessorAttributeChanges = accessorDeclaration.GetAttributeCodeChanges (semanticModel);
var accessorAttributeChanges = accessorDeclaration.GetAttributeCodeChanges (context.SemanticModel);
accessorsBucket.Add (new (
accessorKind: kind,
symbolAvailability: accessorSymbol.GetSupportedPlatforms (),
Expand Down
Loading

0 comments on commit 41e2f0f

Please sign in to comment.