Skip to content

Commit

Permalink
Merge master to dev15.7 (#4475)
Browse files Browse the repository at this point in the history
* One lookup in nenv.eFieldLabels should be enough (#4469)

* Shortcut NameResolution searches (#4444)

* No need to decompile coreDisplayName all the time (#4443)
  • Loading branch information
dotnet-bot authored and KevinRansom committed Mar 9, 2018
1 parent 5276ece commit 3bdd481
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 24 deletions.
41 changes: 30 additions & 11 deletions src/fsharp/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2688,6 +2688,7 @@ let rec ResolvePatternLongIdentPrim sink (ncenv:NameResolver) fullyQualified war
let moduleSearch ad =
ResolveLongIndentAsModuleOrNamespaceThen sink ResultCollectionSettings.AtMostOneResult ncenv.amap m fullyQualified nenv ad lid false
(ResolvePatternLongIdentInModuleOrNamespace ncenv nenv numTyArgsOpt ad)

let tyconSearch ad =
match lid with
| tn :: rest when not (isNil rest) ->
Expand All @@ -2697,15 +2698,33 @@ let rec ResolvePatternLongIdentPrim sink (ncenv:NameResolver) fullyQualified war
ResolveLongIdentInTyconRefs ResultCollectionSettings.AtMostOneResult ncenv nenv LookupKind.Pattern 1 tn.idRange ad rest numTyArgsOpt tn.idRange tcrefs
| _ ->
NoResultsOrUsefulErrors
let resInfo,res,rest =
match AtMostOneResult m (tyconSearch ad +++ moduleSearch ad) with

let resInfo,res,rest =
let tyconResult = tyconSearch ad
match tyconResult with
| Result (res :: _) -> res
| _ ->

let moduleResult = moduleSearch ad
match moduleResult with
| Result (res :: _) -> res
| _ ->

match AtMostOneResult m (tyconResult +++ moduleResult) with
| Result _ as res -> ForceRaise res
| _ ->
ForceRaise (AtMostOneResult m (tyconSearch AccessibleFromSomeFSharpCode +++ moduleSearch AccessibleFromSomeFSharpCode))
| _ ->

let tyconResult = tyconSearch AccessibleFromSomeFSharpCode
match tyconResult with
| Result (res :: _) -> res
| _ ->
ForceRaise (AtMostOneResult m (tyconResult +++ moduleSearch AccessibleFromSomeFSharpCode))

ResolutionInfo.SendEntityPathToSink(sink,ncenv,nenv,ItemOccurence.Use,ad,resInfo,ResultTyparChecker(fun () -> true))

if not (isNil rest) then error(Error(FSComp.SR.nrIsNotConstructorOrLiteral(),(List.head rest).idRange))
res
match rest with
| [] -> res
| element :: _ -> error(Error(FSComp.SR.nrIsNotConstructorOrLiteral(),element.idRange))


/// Resolve a long identifier when used in a pattern.
Expand Down Expand Up @@ -3169,16 +3188,16 @@ let private ResolveExprDotLongIdent (ncenv:NameResolver) m ad nenv typ lid findF
if isAppTy ncenv.g typ then
NoResultsOrUsefulErrors
else
match lid with
match lid with
// A unique record label access, e.g expr.field
| id::rest when nenv.eFieldLabels.ContainsKey(id.idText) ->
match nenv.eFieldLabels.[id.idText] with
| [] -> NoResultsOrUsefulErrors
| rfref :: _ ->
| id::rest ->
match Map.tryFind id.idText nenv.eFieldLabels with
| Some (rfref :: _) ->
// NOTE (instantiationGenerator cleanup): we need to freshen here because we don't know the type.
// But perhaps the caller should freshen??
let item = FreshenRecdFieldRef ncenv m rfref
OneSuccess (ResolutionInfo.Empty,item,rest)
| _ -> NoResultsOrUsefulErrors
| _ -> NoResultsOrUsefulErrors

let search = dotFieldIdSearch
Expand Down
28 changes: 15 additions & 13 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,32 +1405,34 @@ let ComputeAccessAndCompPath env declKindOpt m vis overrideVis actualParent =
let cpath = if accessModPermitted then Some env.eCompPath else None
vis, cpath

let CheckForAbnormalOperatorNames cenv (idRange:range) opName isMember =
if (idRange.EndColumn - idRange.StartColumn <= 5) &&
not cenv.g.compilingFslib
let CheckForAbnormalOperatorNames cenv (idRange:range) coreDisplayName (memberInfoOpt: ValMemberInfo option) =
if (idRange.EndColumn - idRange.StartColumn <= 5) &&
not cenv.g.compilingFslib
then
match opName with
let opName = DecompileOpName coreDisplayName
let isMember = memberInfoOpt.IsSome
match opName with
| PrettyNaming.Relational ->
if isMember then
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidMethodNameForRelationalOperator(opName, (CompileOpName opName)), idRange))
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidMethodNameForRelationalOperator(opName, coreDisplayName), idRange))
else
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidOperatorDefinitionRelational(opName), idRange))
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidOperatorDefinitionRelational opName, idRange))
| PrettyNaming.Equality ->
if isMember then
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidMethodNameForEquality(opName, (CompileOpName opName)), idRange))
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidMethodNameForEquality(opName, coreDisplayName), idRange))
else
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidOperatorDefinitionEquality(opName), idRange))
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidOperatorDefinitionEquality opName, idRange))
| PrettyNaming.Control ->
if isMember then
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidMemberName(opName, (CompileOpName opName)), idRange))
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidMemberName(opName, coreDisplayName), idRange))
else
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidOperatorDefinition(opName), idRange))
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidOperatorDefinition opName, idRange))
| PrettyNaming.Indexer ->
if not isMember then
error(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidIndexOperatorDefinition(opName), idRange))
error(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidIndexOperatorDefinition opName, idRange))
| PrettyNaming.FixedTypes ->
if isMember then
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidMemberNameFixedTypes(opName), idRange))
warning(StandardOperatorRedefinitionWarning(FSComp.SR.tcInvalidMemberNameFixedTypes opName, idRange))
| PrettyNaming.Other -> ()

let MakeAndPublishVal cenv env (altActualParent, inSig, declKind, vrec, (ValScheme(id, typeScheme, topValData, memberInfoOpt, isMutable, inlineFlag, baseOrThis, vis, compgen, isIncrClass, isTyFunc, hasDeclaredTypars)), attrs, doc, konst, isGeneratedEventVal) =
Expand Down Expand Up @@ -1537,7 +1539,7 @@ let MakeAndPublishVal cenv env (altActualParent, inSig, declKind, vrec, (ValSche
(hasDeclaredTypars || inSig), isGeneratedEventVal, konst, actualParent)


CheckForAbnormalOperatorNames cenv id.idRange (DecompileOpName vspec.CoreDisplayName) (Option.isSome memberInfoOpt)
CheckForAbnormalOperatorNames cenv id.idRange vspec.CoreDisplayName memberInfoOpt

PublishValueDefn cenv env declKind vspec

Expand Down

0 comments on commit 3bdd481

Please sign in to comment.