Exemple #1
0
        public BurstProblemSubAnalyzerStatus CheckAndAnalyze(IReferenceExpression referenceExpression, IHighlightingConsumer consumer)
        {
            var element = referenceExpression.Reference.Resolve().DeclaredElement;

            if (!(element is ITypeOwner typeOwner))
            {
                return(BurstProblemSubAnalyzerStatus.NO_WARNING_CONTINUE);
            }

            if (typeOwner is IAttributesOwner attributesOwner &&
                attributesOwner.HasAttributeInstance(KnownTypes.NativeSetClassTypeToNullOnScheduleAttribute, AttributesSource.Self))
            {
                return(BurstProblemSubAnalyzerStatus.NO_WARNING_CONTINUE);
            }

            if (BurstCodeAnalysisUtil.IsBurstPermittedType(typeOwner.Type()))
            {
                return(BurstProblemSubAnalyzerStatus.NO_WARNING_CONTINUE);
            }

            consumer?.AddHighlighting(new BurstLoadingManagedTypeWarning(
                                          referenceExpression,
                                          typeOwner.Type().GetTypeElement()?.ShortName));

            return(BurstProblemSubAnalyzerStatus.WARNING_PLACED_STOP);
        }
Exemple #2
0
        public BurstProblemSubAnalyzerStatus CheckAndAnalyze(IInvocationExpression invocationExpression, IHighlightingConsumer consumer)
        {
            var invokedMethod = invocationExpression.Reference.Resolve().DeclaredElement as IMethod;

            if (!BurstCodeAnalysisUtil.IsSharedStaticCreateMethod(invokedMethod))
            {
                return(BurstProblemSubAnalyzerStatus.NO_WARNING_CONTINUE);
            }

            if (invokedMethod.TypeParameters.Count != 0)
            {
                return(BurstProblemSubAnalyzerStatus.NO_WARNING_STOP);
            }

            var methodParameters = invokedMethod.Parameters;

            for (var index = 0; index < methodParameters.Count - 1; index++)
            {
                if (!methodParameters[index].Type.IsSystemType())
                {
                    return(BurstProblemSubAnalyzerStatus.NO_WARNING_STOP);
                }
            }

            consumer?.AddHighlighting(new BurstSharedStaticCreateWarning(invocationExpression));

            return(BurstProblemSubAnalyzerStatus.WARNING_PLACED_STOP);
        }
            public override bool InteriorShouldBeProcessed(ITreeNode element)
            {
                SeldomInterruptChecker.CheckForInterrupt();

                if (element == StartTreeNode)
                {
                    return(true);
                }

                return(!UnityCallGraphUtil.IsFunctionNode(element) && !BurstCodeAnalysisUtil.IsBurstProhibitedNode(element));
            }
Exemple #4
0
        protected override bool AnalyzeNode(IAssignmentExpression navigated, ICSharpExpression from)
        {
            var lhs = navigated.Dest;
            var rhs = navigated.Source;

            if (BurstCodeAnalysisUtil.IsFixedString(lhs.Type()) && rhs.Type().IsString())
            {
                return(false);
            }

            return(true);
        }
        public static bool IsAvailable([CanBeNull] IMethodDeclaration methodDeclaration)
        {
            if (methodDeclaration == null)
            {
                return(false);
            }

            var declaredElement = methodDeclaration.DeclaredElement;

            return(declaredElement != null && methodDeclaration.IsValid() &&
                   !BurstCodeAnalysisUtil.IsBurstProhibitedFunction(declaredElement));
        }
Exemple #6
0
        public static bool IsAvailable([CanBeNull] IMethodDeclaration methodDeclaration)
        {
            if (methodDeclaration == null)
            {
                return(false);
            }

            methodDeclaration.GetPsiServices().Locks.AssertReadAccessAllowed();

            var declaredElement = methodDeclaration.DeclaredElement;

            return(declaredElement != null && methodDeclaration.IsValid() &&
                   !BurstCodeAnalysisUtil.IsBurstProhibitedFunction(declaredElement));
        }
Exemple #7
0
        protected override void Analyze(IInvocationExpression invocationExpression, IDaemonProcess daemonProcess,
                                        DaemonProcessKind kind, IHighlightingConsumer consumer)
        {
            var invokedMethod = invocationExpression.Reference.Resolve().DeclaredElement as IMethod;

            if (!BurstCodeAnalysisUtil.IsSharedStaticCreateMethod(invokedMethod))
            {
                return;
            }

            var substitution       = invocationExpression.Reference.Resolve().Substitution;
            var domain             = substitution.Domain;
            var sharedStaticDomain = domain.Where(parameter =>
                                                  parameter.OwnerType is IStruct @struct && @struct.GetClrName().Equals(KnownTypes.SharedStatic))
                                     .ToList();

            Assertion.Assert(sharedStaticDomain.Count == 1, "SharedStatic should have 1 substitution");

            if (sharedStaticDomain.Count != 1)
            {
                return;
            }

            var typeParameter = sharedStaticDomain[0];

            // it means Burst finally supported type parameter unmanaged constraint
            Assertion.Assert(!typeParameter.IsUnmanagedType, "SharedStatic doesn't have unmanaged constraint");

            if (!typeParameter.IsValid() || typeParameter.IsUnmanagedType)
            {
                return;
            }

            var substitutedType = substitution.Apply(typeParameter);

            if (substitutedType.IsUnmanagedType(invocationExpression.GetLanguageVersion()))
            {
                return;
            }

            var typeParameterName = substitutedType.GetTypeElement()?.ShortName;

            if (typeParameterName != null)
            {
                consumer.AddHighlighting(new SharedStaticUnmanagedTypeWarning(invocationExpression, typeParameterName));
            }
        }
        protected override bool AnalyzeNode(ICSharpArgument navigated, ICSharpExpression from)
        {
            var invocationExpression = InvocationExpressionNavigator.GetByArgument(navigated);

            if (invocationExpression != null)
            {
                var callee = invocationExpression.Reference.Resolve().DeclaredElement as IMethod;

                if (BurstCodeAnalysisUtil.IsBurstPossibleArgumentString(navigated) &&
                    callee != null &&
                    (BurstCodeAnalysisUtil.IsDebugLog(callee) ||
                     BurstCodeAnalysisUtil.IsStringFormat(callee)))
                {
                    return(false);
                }
            }


            return(true);
        }
        protected override bool AnalyzeNode(IExpressionInitializer navigated, ICSharpExpression from)
        {
            Assertion.Assert(ReferenceEquals(navigated.Value, from), "navigated should be from");

            var initializerOwnerDeclaration = navigated.GetContainingNode <IInitializerOwnerDeclaration>();
            var initializer = initializerOwnerDeclaration?.Initializer;

            if (ReferenceEquals(initializer, navigated))
            {
                var typeOwner = initializerOwnerDeclaration.DeclaredElement as ITypeOwner;
                var type      = typeOwner?.Type;

                if (BurstCodeAnalysisUtil.IsFixedString(type))
                {
                    return(false);
                }
            }


            return(true);
        }
Exemple #10
0
        public override LocalList <IDeclaredElement> GetBanMarksFromNode(ITreeNode currentNode, IDeclaredElement containingFunction)
        {
            var result = base.GetBanMarksFromNode(currentNode, containingFunction);

            if (containingFunction == null)
            {
                return(result);
            }

            var functionDeclaration = currentNode as IFunctionDeclaration;
            var function            = functionDeclaration?.DeclaredElement;

            if (function == null)
            {
                return(result);
            }

            if (BurstCodeAnalysisUtil.IsBurstProhibitedFunction(function))
            {
                result.Add(function);
            }

            return(result);
        }
Exemple #11
0
        public static bool CheckAndAnalyze(ITreeNode node, IHighlighting highlighting, IHighlightingConsumer consumer)
        {
            var firstNode = node;

            do
            {
                var parent = node.Parent;

                if (parent is IExpressionInitializer expressionInitializer)
                {
                    if (ReferenceEquals(expressionInitializer.Value, firstNode))
                    {
                        do
                        {
                            node   = parent;
                            parent = node.Parent;
                        } while (parent != null && !(parent is IInitializerOwnerDeclaration));

                        if (parent == null)
                        {
                            return(true);
                        }

                        var initializerOwnerDeclaration = (IInitializerOwnerDeclaration)parent;
                        if (ReferenceEquals(initializerOwnerDeclaration.Initializer, expressionInitializer))
                        {
                            var typeOwner = initializerOwnerDeclaration.DeclaredElement as ITypeOwner;
                            var type      = typeOwner?.Type;
                            if (BurstCodeAnalysisUtil.IsFixedString(type))
                            {
                                return(false);
                            }
                        }
                    }

                    consumer?.AddHighlighting(highlighting);
                    return(true);
                }

                if (parent is ICSharpArgument cSharpArgument)
                {
                    var invocationInfo = cSharpArgument.Invocation;
                    if (invocationInfo is IInvocationExpression info)
                    {
                        var callee = CallGraphUtil.GetCallee(info) as IMethod;

                        if (BurstCodeAnalysisUtil.IsBurstPermittedString(cSharpArgument.GetExpressionType().ToIType()) &&
                            callee != null &&
                            (BurstCodeAnalysisUtil.IsDebugLog(callee) ||
                             BurstCodeAnalysisUtil.IsStringFormat(callee)))
                        {
                            return(false);
                        }
                    }

                    consumer?.AddHighlighting(highlighting);
                    return(true);
                }

                if (parent is IAssignmentExpression assignmentExpression)
                {
                    if (assignmentExpression.Dest == node)
                    {
                        return(false);
                    }

                    if (BurstCodeAnalysisUtil.IsFixedString(assignmentExpression.Dest.Type()) &&
                        assignmentExpression.Source.Type().IsString())
                    {
                        return(false);
                    }

                    consumer?.AddHighlighting(highlighting);
                    return(true);
                }

                if (parent is ITypeMemberDeclaration)
                {
                    consumer?.AddHighlighting(highlighting);
                    return(true);
                }

                node = parent;
            } while (node != null);

            consumer?.AddHighlighting(highlighting);
            return(true);
        }
Exemple #12
0
        public static bool CheckAndAnalyze(ICSharpExpression startNode, IHighlighting highlighting,
                                           IHighlightingConsumer consumer)
        {
            var firstNode = startNode;

            do
            {
                var parent = startNode.Parent;

                switch (parent)
                {
                case IExpressionInitializer expressionInitializer:
                {
                    if (ReferenceEquals(expressionInitializer.Value, firstNode))
                    {
                        do
                        {
                            parent = parent.Parent;
                        } while (parent != null && !(parent is IInitializerOwnerDeclaration));

                        if (parent == null)
                        {
                            return(true);
                        }

                        var initializerOwnerDeclaration = (IInitializerOwnerDeclaration)parent;

                        if (ReferenceEquals(initializerOwnerDeclaration.Initializer, expressionInitializer))
                        {
                            var typeOwner = initializerOwnerDeclaration.DeclaredElement as ITypeOwner;
                            var type      = typeOwner?.Type;

                            if (BurstCodeAnalysisUtil.IsFixedString(type))
                            {
                                return(false);
                            }
                        }
                    }

                    consumer?.AddHighlighting(highlighting);
                    return(true);
                }

                case ICSharpArgument cSharpArgument:
                {
                    var invocationInfo = cSharpArgument.Invocation;

                    if (invocationInfo is IInvocationExpression invocationExpression)
                    {
                        var callee = invocationExpression.Reference.Resolve().DeclaredElement as IMethod;

                        if (BurstCodeAnalysisUtil.IsBurstPossibleArgumentString(cSharpArgument) &&
                            callee != null &&
                            (BurstCodeAnalysisUtil.IsDebugLog(callee) ||
                             BurstCodeAnalysisUtil.IsStringFormat(callee)))
                        {
                            return(false);
                        }
                    }

                    consumer?.AddHighlighting(highlighting);
                    return(true);
                }

                case IAssignmentExpression assignmentExpression
                    when assignmentExpression.Dest == startNode ||
                    BurstCodeAnalysisUtil.IsFixedString(assignmentExpression.Dest.Type()) &&
                    assignmentExpression.Source.Type().IsString():
                    return(false);

                case IAssignmentExpression _:
                case ITypeMemberDeclaration _:
                    consumer?.AddHighlighting(highlighting);
                    return(true);

                case ICSharpExpression expression:
                    startNode = expression;
                    break;

                default:
                    startNode = null;
                    break;
                }
            } while (startNode != null);

            consumer?.AddHighlighting(highlighting);
            return(true);
        }